Wednesday, 26 December 2012
HTML Snippet- Make This Site Your Home Page
When designing your web site, providing your visitors with a way to make your web site their start up home page provides a great way to obtain repeat traffic. Not only can this increase your web site traffic, but it can also increase your sales.
This JavaScript code will enable you to place a button on your site that, when clicked on, will make your web site your visitors home page.
Place the following code where you would like the button to appear.
This JavaScript code will enable you to place a button on your site that, when clicked on, will make your web site your visitors home page.
Place the following code where you would like the button to appear.
');"> |
Change the text indicated in red to your web address beginning with http://
HTML-Redirect to a New Page
If you need to redirect your visitors to a new page, this HTML redirect code may be just what you're looking for.
When designing a web site, many times you must change the location of a web page. However, if the page is popular, your visitors may have already linked to it. In addition, the Search Engines have most-likely already indexed the page.
For this reason, it is best to replace your page with a new page that will redirect your visitors to the new page. This provides a great way to provide your visitors with the information they were looking for and prevent you from losing your traffic.
However, when using this HTML redirect code, please ensure that you don't use it to trick the Search Engines, as this could get your web site banned. It is always best to work hard and learn quality ways in which to drive traffic to your web site.
Place the following HTML redirect code between the and tags of your HTML code.
When designing a web site, many times you must change the location of a web page. However, if the page is popular, your visitors may have already linked to it. In addition, the Search Engines have most-likely already indexed the page.
For this reason, it is best to replace your page with a new page that will redirect your visitors to the new page. This provides a great way to provide your visitors with the information they were looking for and prevent you from losing your traffic.
However, when using this HTML redirect code, please ensure that you don't use it to trick the Search Engines, as this could get your web site banned. It is always best to work hard and learn quality ways in which to drive traffic to your web site.
Place the following HTML redirect code between the and tags of your HTML code.
The above HTML redirect code will redirect your visitors to another web page instantly. The content="0; may be changed to the number of seconds you want the browser to wait before redirecting.
Wednesday, 19 December 2012
Saturday, 15 December 2012
Tuesday, 11 December 2012
Monday, 10 December 2012
Sunday, 9 December 2012
Paradesi audio release
Saturday, 8 December 2012
Skip or Bypass the Adfly ,Adcroft and Adfoc Shortener URL Links
These are the URL shorteners and they helps to the sites like they pay when the People are open the websites and these Url links are come while the Before Article Opens.And these Adf.ly ,Adfoc,Adcroft and Linkbucks are pay $5 for 10000 page Views .
These Links are Very Disturbing to you because of when you are open a link these URL comes and it says wait for 5 seconds and after you Click the Skip the Add Button . So this is the Long Process so we are providing the Trick in the Article Remove this URLs Automatically by Two ways .
Using AdsFight! :-
AdsFight! is the tool and simple Userscript which fight with the Adds and By this you can skip or Bypass the Adf.ly and etc URL 's.This can be available for Google Chrome and Firefox Users .
For Chrome :-
For Mozilla Firefox:-
Using DeadFly :-
DeadFly is the Online Bypasser tool which skips or Bypass the shorteners URL's like Adf.ly,Adcroft and Adfoc.
Note :-
I supposed to Choose 1 method that is by using AdsFight! because it is the onetime Installation and second one is takes sometime . So use the AdsFight and Skip the Annoying URL's . Use DesdFly also .
That's It . If you Like this Article Share With Your Friends .Thank You For Visiting .
These Links are Very Disturbing to you because of when you are open a link these URL comes and it says wait for 5 seconds and after you Click the Skip the Add Button . So this is the Long Process so we are providing the Trick in the Article Remove this URLs Automatically by Two ways .
Using AdsFight! :-
AdsFight! is the tool and simple Userscript which fight with the Adds and By this you can skip or Bypass the Adf.ly and etc URL 's.This can be available for Google Chrome and Firefox Users .
For Chrome :-
- If you using Chrome Browser Just Install the AdsFight!userscript from Here .
- And Next Click the Install Button .
- That's all it will Skips Adds or Bypass the Adds Automatically when you are click on them .
For Mozilla Firefox:-
- If you Using Mozilla Firefox First you have to install the Greasemonkey App in your Browser and then Install the same Ads Fight!
Using DeadFly :-
DeadFly is the Online Bypasser tool which skips or Bypass the shorteners URL's like Adf.ly,Adcroft and Adfoc.
- And next You just need to go to their website and paste the Adf.ly or Adcraft.co link and press Deadfly , and next you directly go to their Website .
Note :-
I supposed to Choose 1 method that is by using AdsFight! because it is the onetime Installation and second one is takes sometime . So use the AdsFight and Skip the Annoying URL's . Use DesdFly also .
That's It . If you Like this Article Share With Your Friends .Thank You For Visiting .
INTERNET & TECHNOLOGY - Tips n Tricks !!!: Free BSNL 3G Unlimited Internet Trick & Hack 2012
INTERNET & TECHNOLOGY - Tips n Tricks !!!: Free BSNL 3G Unlimited Internet Trick & Hack 2012: Hi Friends!! Today iam with the New Trick and Hack For Bsnl users. Recently I give you to the Requirements :- 1) You Must Have the 3...
Friday, 7 December 2012
வைரஸ் தாக்கிய ‘பென்ட்ரைவ்’ இலிருந்து பைல்களை மீட்க சிம்பிள் வழி!
தற்பொழுது தகவல்களை சேமிக்க பெரும்பாலானவர்களால் பயன்படுத்தப்படுவது USB பென்
டிரைவ்கள்.
இதில் முக்கியமான பிரச்சினை வைரஸ் பிரச்சினை. வெவ்வேறான கணனிகளில்
உபயோகிப்பதால் வைரஸ்கள் சுலபமாக பென்டிரைவில் புகுந்து உள்ளே
இருக்கும்பைல்களை பாதிக்கிறது.
இப்படி பாதிக்கும் பொழுதுஉங்கள் பென்ட்ரைவில் உள்ளபைல்கள் மறைக்கப்பட்டுவிடும் கணனியில் பென்டிரைவை
ஓப்பன் செய்தால் எந்த பைல்களும் இருக்காது. வெற்றிடமாக இருக்கும். ஆனால் properties சென்று பார்த்தால் பைல்கள் இருப்பது போன்றே அளவு காட்டும். காரணம் நம் தகவல்களை வைரஸ்கள் மறைத்து வைத்துவிட்டது. பென்டிரைவில் முக்கியமான தவல்கள் ஏதும் இல்லை எனில் Format செய்து பென்டிரைவை திரும்ப பெறலாம். ஆனால் ஏதேனும் முக்கிய மான தகவல்கள் இருந்தால் எப்படி அந்த பைல்களை பத்திரமாக மீண்டும் கொண்டு வருவது என பார்ப்போம்.
இதற்க்கு நீங்கள் எந்த மென்பொருளையும் உங்கள் கணினியில் Install செய்து உபயோகிக்க வேண்டியதில்லை.உங்கள் கணனியிலேயே சுலபமாக செய்து விடலாம். கீழே உள்ள வழிமுறையின் படி கவனமாக செய்து அந்த பைல்களை மீட்டு எடுங்கள்.
1) முதலில் பென்டிரைவை உங்கள் கணினியில் சொருகி கொள்ளுங்கள்.
2) Start ==> Run ==> CMD==> Enter கொடுக்கவும்.
3) இப்பொழுது பென்ட்ரைவ் எந்த ட்ரைவில் உள்ளது என பாருங்கள். My Computer செல்வதன் மூலம் கண்டறியலாம்.
4) உதாரணமாக E: டிரைவில் பென்ட்ரைவ் இருக்கிறது எனவைத்து கொள்வோம் அதற்கு நீங்கள் E: என கொடுத்து Enter அழுத்தவும்.
5) attrib -h -s -r /s /d *.*என டைப் செய்யுங்கள் ஒவ்வொருபகுதிக்கும் Space சரியாககொடுக்கவும்.
◦நீங்கள் சரியாக கொடுத்துஉள்ளீர்கள் என உறுதி செய்து கொண்டு Enter அழுத்துங்கள்.
◦சில வினாடிகள் பொறுத்திருங்கள். இப்பொழுது உங்கள் பென்ட்ரைவ் சோதித்து பாருங்கள் உங்களுடைய பைல்கள் அனைத்தும் திரும்பவும் வந்திருக்கும் —
உபயோகமான தகவல் என்று நினைத்தால், நண்பர்களுடன் பகிருங்கள்...
இப்படி பாதிக்கும் பொழுதுஉங்கள் பென்ட்ரைவில் உள்ளபைல்கள் மறைக்கப்பட்டுவிடும் கணனியில் பென்டிரைவை
ஓப்பன் செய்தால் எந்த பைல்களும் இருக்காது. வெற்றிடமாக இருக்கும். ஆனால் properties சென்று பார்த்தால் பைல்கள் இருப்பது போன்றே அளவு காட்டும். காரணம் நம் தகவல்களை வைரஸ்கள் மறைத்து வைத்துவிட்டது. பென்டிரைவில் முக்கியமான தவல்கள் ஏதும் இல்லை எனில் Format செய்து பென்டிரைவை திரும்ப பெறலாம். ஆனால் ஏதேனும் முக்கிய மான தகவல்கள் இருந்தால் எப்படி அந்த பைல்களை பத்திரமாக மீண்டும் கொண்டு வருவது என பார்ப்போம்.
இதற்க்கு நீங்கள் எந்த மென்பொருளையும் உங்கள் கணினியில் Install செய்து உபயோகிக்க வேண்டியதில்லை.உங்கள் கணனியிலேயே சுலபமாக செய்து விடலாம். கீழே உள்ள வழிமுறையின் படி கவனமாக செய்து அந்த பைல்களை மீட்டு எடுங்கள்.
1) முதலில் பென்டிரைவை உங்கள் கணினியில் சொருகி கொள்ளுங்கள்.
2) Start ==> Run ==> CMD==> Enter கொடுக்கவும்.
3) இப்பொழுது பென்ட்ரைவ் எந்த ட்ரைவில் உள்ளது என பாருங்கள். My Computer செல்வதன் மூலம் கண்டறியலாம்.
4) உதாரணமாக E: டிரைவில் பென்ட்ரைவ் இருக்கிறது எனவைத்து கொள்வோம் அதற்கு நீங்கள் E: என கொடுத்து Enter அழுத்தவும்.
5) attrib -h -s -r /s /d *.*என டைப் செய்யுங்கள் ஒவ்வொருபகுதிக்கும் Space சரியாககொடுக்கவும்.
◦நீங்கள் சரியாக கொடுத்துஉள்ளீர்கள் என உறுதி செய்து கொண்டு Enter அழுத்துங்கள்.
◦சில வினாடிகள் பொறுத்திருங்கள். இப்பொழுது உங்கள் பென்ட்ரைவ் சோதித்து பாருங்கள் உங்களுடைய பைல்கள் அனைத்தும் திரும்பவும் வந்திருக்கும் —
உபயோகமான தகவல் என்று நினைத்தால், நண்பர்களுடன் பகிருங்கள்...
Inheritance Mapping In Hibernate – Introduction
Compared to JDBC we have one main advantage in hibernate, which is hibernate inheritance. Suppose if we have base and derived classes, now if we save derived(sub) class object, base class object will also be stored into the database.
But the thing is we must specify in what table we need to save which object data ( i will explain about this point later, just remember as of now).
For Example:
1
2
3
4
| class Payment { // content will goes hear } |
1
2
3
4
| class CreditCard extends Payment { // content will goes hear } |
- See if you save CreditCard class object, then payment class object will also be saved into the database
- Table per class hierarchy
- Table per sub-class hierarchy
- Table per concrete class hierarchy
Will see these 3 Inheritance Mappings in depth___, friends ensure you are clear about all previous concepts so far we covered, if not so you may not understand further, please refer once if you have any doubts.
Hibernate Lifecycle Of pojo Class Objects
Actually our POJO class object having 3 states like…
- Transient state
- Persistent state
- Detached state
Transient & Persistent states:
- When ever an object of a pojo class is created then it will be in the Transient state
- When the object is in a Transient state it doesn’t represent any row of the database, i mean not associated with any Session object, if we speak more we can say no relation with the database its just an normal object
- If we modify the data of a pojo class object, when it is in transient state then it doesn’t effect on the database table
- When the object is in persistent state, then it represent one row of the database, if the object is in persistent state then it is associated with the unique Session
- if we want to move an object from persistent to detached state, we need to do either closing that session or need to clear the cache of the session
- if we want to move an object from persistent state into transient state then we need to delete that object permanently from the database
Example____ ClientProgram.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
| import org.hibernate.*; import org.hibernate.cfg.*; public class ClientProgram { public static void main(String[] args) { Configuration cfg = new Configuration(); cfg.configure( "hibernate.cfg.xml" ); SessionFactory factory = cfg.buildSessionFactory(); Session session = factory.openSession(); // Transient state_____start Product p= new Product(); p.setProductId( 101 ); p.setProName( "iPhone" ); p.setPrice( 25000 ); // Transient state_____end // Persistent state_____start Transaction tx = session.beginTransaction(); session.save(p); System.out.println( "Object saved successfully.....!!" ); tx.commit(); // Persistent state_____end session.close(); factory.close(); } } |
- see the above client program, line numbers 16 to 19 we just loaded the object and called the corresponding setter methods, its not related to the database row
- if you see, line number 24 we called save method in the Session Interface, means the object is now having the relation with the database
- if we want to convert the object from Transient state to Persistentstate we can do in 2 ways
- By saving that object like above
- By loading object from database
If we want to save an object into database then we need to call any one of the following 3 methods
- save()
- persist()
- saveOrUpdate()
If we want to load an object from database, then we need to call either load() or get() methods
Transient:
One newly created object,with out having any relation with the database, means never persistent, not associated with any Session objectPersistent:
Having the relation with the database, associated with a unique Session objectDetached:
previously having relation with the database [persistent ], now not associated with any Sessionsee the next sessions for the better understanding of the life cycle states of pojo class object(s) the hibernate
Example On Hibernate Update Query
This is the program to update an object (1 complete row) in the database, which is already persisted in the database, then we have the following two approaches…
Approach 1
Load that object from the database, and modify its values, now hibernate automatically modifies the values on to database also, when ever the transaction is committed.Approach 2:
If we want to modify object in the database, then create new object with same id and we must call update() given by session interface.Files required to execute this program..
- Product.java (My POJO class)
- product.hbm.xml (Xml mapping file )
- hibernate.cfg.xml (Xml configuration file)
- ClientProgram.java(java file to write our hibernate logic)
Related to approach 1:
Product.java (POJO)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
| package str; public class Product{ private int productId; private String proName; private double price; public void setProductId( int productId) { this .productId = productId; } public int getProductId() { return productId; } public void setProName(String proName) { this .proName = proName; } public String getProName() { return proName; } public void setPrice( double price) { this .price = price; } public double getPrice() { return price; } } |
Product.hbm.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
"-//Hibernate/Hibernate Mapping DTD 3.0//EN" < hibernate-mapping > < class name = "str.Product" table = "products" > < id name = "productId" column = "pid" /> < property name = "proName" column = "pname" length = "10" /> < property name = "price" /> </ class > </ hibernate-mapping > |
hibernate.cfg.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
"-//Hibernate/Hibernate Configuration DTD 3.0//EN" < hibernate-configuration > < session-factory > < property name = "connection.driver_class" >oracle.jdbc.driver.OracleDriver </ property > < property name = "connection.url" >jdbc:oracle:thin:@www.java4s.com:1521:XE</ property > < property name = "connection.username" >system</ property > < property name = "connection.password" >admin</ property > < property name = "dialect" >org.hibernate.dialect.OracleDialect</ property > < property name = "show_sql" >true</ property > < property name = "hbm2ddl.auto" >update</ property > < mapping resource = "Product.hbm.xml" ></ mapping > </ session-factory > </ hibernate-configuration > |
ClientProgram.java (* Recommended way)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
| package str; import org.hibernate.*; import org.hibernate.cfg.*; public class ForOurLogic { public static void main(String[] args) { Configuration cfg = new Configuration(); cfg.configure( "hibernate.cfg.xml" ); SessionFactory factory = cfg.buildSessionFactory(); Session session = factory.openSession(); Object o=session.load(Product. class , new Integer( 105 )); Product s=(Product)o; Transaction tx = session.beginTransaction(); //s.setStno(105); should not update, because we loaded with that number right..? s.setPrice( 4000 ); // implicitly update method will be called.. tx.commit(); System.out.println( "Object Updated successfully.....!!" ); session.close(); factory.close(); } } |
- See line number 20, actually there i tried to update
Stno(105),
we should not do this, because we have loaded the object from the database with his id number only, see line number 16, if we update hibernate will rises the exception - See line number 24 once we call the commit(), automatically update method will be called by hibernate.
- When ever an object is loaded from the database then hibernate stores the loaded object in cache-memory maintained by session-interface
- Once an object is loaded, if we do any modifications on that object by calling its setter methods, then these modification are stored in the object maintained by cache-memory
- if we modify the loaded object for multiple times then also the modifications will be stored in object maintained by the cache-memory only.
- when ever we issue commit() operation then hibernate verify whether any changes are there between the object stored in the cache and object in the database, if changes exists then hibernate automatically updates the database by generating any update operation.
- What am saying is hibernate automatically maintains synchronization between cache-memory object and database table objects (rows)
Related to approach 2:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
| package str; import org.hibernate.*; import org.hibernate.cfg.*; public class ForOurLogic { public static void main(String[] args) { Configuration cfg = new Configuration(); cfg.configure( "hibernate.cfg.xml" ); SessionFactory factory = cfg.buildSessionFactory(); Session session = factory.openSession(); Product p= new Product(); p.setProductId( 104 ); // 104 must be in the DB p.setProName( "Someting" ); Transaction tx = session.beginTransaction(); session.update(p); tx.commit(); System.out.println( "Object Updated successfully.....!!" ); session.close(); factory.close(); } } |
Difference Between Hibernate Save And Persist Methods
Actually the difference between hibernate save() and persist() methods is depends on generator class we are using.
- If our generator class is assigned, then there is no difference between save() and persist() methods. Because generator ‘assigned’ means, as a programmer we need to give the primary key value to save in the database right [ Hope you know this generators concept ]
- In case of other than assigned generator class, suppose if our generator class name is Increment means hibernate it self will assign the primary key id value into the database right [ other than assigned generator, hibernate only used to take care the primary key id value remember ], so in this case if we call save() or persist() method then it will insert the record into the database normally
long s = session.save(k);In this same case, persist() will never give any value back to the client, hope you are clear.
Main Advantage And Disadvantages Of Hibernates
Advantages of hibernates:
- Hibernate supports Inheritance, Associations, Collections
- In hibernate if we save the derived class object, then its base class object will also be stored into the database, it means hibernate supporting inheritance
- Hibernate supports relationships like One-To-Many,One-To-One, Many-To-Many-to-Many, Many-To-One
- This will also supports collections like List,Set,Map (Only new collections)
- In jdbc all exceptions are checked exceptions, so we must write code in try, catch and throws, but in hibernate we only have Un-checked exceptions, so no need to write try, catch, or no need to write throws. Actually in hibernate we have the translator which converts checked to Un-checked
- Hibernate has capability to generate primary keys automatically while we are storing the records into database
- Hibernate has its own query language, i.e hibernate query language which is database independent
- So if we change the database, then also our application will works as HQL is database independent
- HQL contains database independent commands
- While we are inserting any record, if we don’t have any particular table in the database, JDBC will rises an error like “View not exist”, and throws exception, but in case of hibernate, if it not found any table in the database this will create the table for us
- Hibernate supports caching mechanism by this, the number of round trips between an application and the database will be reduced, by using this caching technique an application performance will be increased automatically.
- Hibernate supports annotations, apart from XML
- Hibernate provided Dialect classes, so we no need to write sql queries in hibernate, instead we use the methods provided by that API.
- Getting pagination in hibernate is quite simple.
Disadvantages of hibernates:
- I don’t think there are disadvantages in hibernate
- You know some thing.., Its saying hibernate is little slower than pure JDBC, actually the reason being hibernate used to generate many SQL statements in run time, but i guess this is not the disadvantage
- But there is one major disadvantage, which was boilerplate code issue, actually we need to write same code in several files in the same application, but spring eliminated this
Example On Hibernate Pagination With Servlet In Eclipse
example on hibernate pagination with servlet..
- when response for request is too large [If we have 1000's of records in the database] then instead of displaying all records at a time on browser we can display the response page by page manner using pagination mechanism
- In pagination, initially one page response will be displayed and we will get links for getting the next pages response
- In this servelt & hibernate integration, we are going to display 4 records or 4 objects of products using hibernate for selecting the data and we will get links to display the records of the next pages
Regarding Logic In Order To Get pagination
- The servlet accepts pageIndex parameter and if the parameter is passed then servlet takes the given number as pageIndex, otherwise the servlet will takes the pageIndex as one [ 1 ]
- Servlet uses Criteria API and the pagination methods of Criteria for loading the records (objects) related to that particular page, and servlet display those records on the browser
- In servlet we use Criteria with projection for finding the total number of records available in the table, and we store that number into the variable
- We will find out the number of hyperlinks required by dividing the total number of records with records per page
- we need to use a loop in order to display the links on the browser, while creating each link, we use the <a href /> to servlet url pattern [Hiper reference] and by passing that page nomber as value for pageIndex parameter
Hibernate Pagination Example In Eclipse
Mates, let see one real time example on this hibernate pagination with servletfiles required…
- Pagination.java
- Product.java
- Product.hbm.xml
- hibernate.cfg.xml
- web.xml
Open eclipse –> New –> Dynamic Web Project
- src folder contains all *.java files
- build folder contains all *.class files in side classes folder
- Hibernate related xml’s hibernate.cfg.xml, mapping files should be in classes folder only
product.java
public class Product{ private int productId; private String proName; private double price; public void setProductId( int productId) { this .productId = productId; } public int getProductId() { return productId; } public void setProName(String proName) { this .proName = proName; } public String getProName() { return proName; } public void setPrice( double price) { this .price = price; } public double getPrice() { return price; } } |
Product.xml
"-//Hibernate/Hibernate Mapping DTD 3.0//EN" < hibernate-mapping > < class name = "com.java4s.hservlet.pagination.Product" table = "products" > < id name = "productId" column = "pid" /> < property name = "proName" column = "pname" length = "10" /> < property name = "price" /> </ class > </ hibernate-mapping > |
hibernate.cfg.xml
"-//Hibernate/Hibernate Configuration DTD 3.0//EN" < hibernate-configuration > < session-factory > < property name = "connection.driver_class" >oracle.jdbc.driver.OracleDriver </ property > < property name = "connection.url" >jdbc:oracle:thin:@www.java4s.com:1521:XE</ property > < property name = "connection.username" >system</ property > < property name = "connection.password" >admin</ property > < property name = "dialect" >org.hibernate.dialect.OracleDialect</ property > < property name = "show_sql" >true</ property > < property name = "hbm2ddl.auto" >update</ property > < mapping resource = "Product.hbm.xml" ></ mapping > </ session-factory > </ hibernate-configuration > |
Pagination.java
import java.io.IOException; import java.io.PrintWriter; import java.util.Iterator; import java.util.List; import javax.servlet.ServletConfig; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServlet; import org.hibernate.Criteria; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.cfg.Configuration; import org.hibernate.criterion.Projections; public class Pagination extends HttpServlet { SessionFactory factory; //init method started public void init(ServletConfig config) throws ServletException { factory = new Configuration().configure().buildSessionFactory(); System.out.println( "Factory has been created...." ); } //init method end //service method start public void service(ServletRequest req, ServletResponse res) throws ServletException,IOException { int pageIndex = 0 ; int totalNumberOfRecords = 0 ; int numberOfRecordsPerPage = 4 ; String sPageIndex = req.getParameter( "pageIndex" ); if (sPageIndex == null ) { pageIndex = 1 ; } else { pageIndex = Integer.parseInt(sPageIndex); } Session ses = factory.openSession(); int s = (pageIndex*numberOfRecordsPerPage) -numberOfRecordsPerPage; Criteria crit = ses.createCriteria(Product. class ); crit.setFirstResult(s); crit.setMaxResults(numberOfRecordsPerPage); List l = crit.list(); Iterator it = l.iterator(); PrintWriter pw = res.getWriter(); pw.println( " ); pw.println( "
); pw.println( " ); pw.println( " |
);
while
(it.hasNext())
{
Product p = (Product)it.next();
pw.println(
"
"
);
pw.println(
""
+p.getProductId()+
"
);
pw.println(
""
+p.getProName()+
"
);
pw.println(
""
+p.getPrice()+
"
);
pw.println(
"
);
}
pw.println(
""
);
Criteria crit1 = ses.createCriteria(Product.
class
);
crit1.setProjection(Projections.rowCount());
List l1=crit1.list();
// pw.println(l1.size());
//returns 1, as list() is used to execute the query if true will returns 1
Iterator it1 = l1.iterator();
if
(it1.hasNext())
{
Object o=it1.next();
totalNumberOfRecords = Integer.parseInt(o.toString());
}
int
noOfPages = totalNumberOfRecords/numberOfRecordsPerPage;
if
(totalNumberOfRecords > (noOfPages * numberOfRecordsPerPage))
{
noOfPages = noOfPages +
1
;
}
for
(
int
i=
1
;i<=noOfPages;i++)
{
String myurl =
"ind?pageIndex="
+i;
);
}
ses.close();
pw.close();
}
//service method end
//destroy method start
public
void
destroy()
{
factory.close();
}
//destroy end
}
- We must create the SessionFactory object in the init() only, as it is the heavy weight one
- and nothing to explain, just read slowly. If you got struck at any point just fire a question in our forum, and see line number 101, ind?pageIndex (ind is my url pattern)
web.xml
< web-app > < servlet > < servlet-name >dummyName</ servlet-name > < servlet-class >com.java4s.hservlet.pagination.Pagination</ servlet-class > </ servlet > < servlet-mapping > < servlet-name >dummyName</ servlet-name > < url-pattern >/ind</ url-pattern > </ servlet-mapping > </ web-app > |
Right click on the project root — > run –> Run on Server
Subscribe to:
Posts (Atom)