Struts Token Feature will be very much useful in common problems like Refresh Button, Back Button, double form submissions etc.
Most often after successful submission of the form just you redirect to your Home Page. Why because if you use RequestDispatcher.forward() method, this will not change the URL of the browser, so if the user presses Refresh Button or F5 Button or Back Button, the same form will be again submitted and you will get another record in side database. So we can use response.sendRedirect() method only to avoid refresh problems.
If we have a perfect tracking Id, say if a user is paying his credit card bill, if you uniquely identify that user with bill number plus due date kind of combinations, your logic should prevent the duplicate form submissions. Another idea is if you can store the values some where for sometime, if same kind of values are coming from the same user then you can decide if its is a fresh request or a duplicate post.
Struts has a token feature that puts a single-use token on a form to prevent duplicate submits. Redirecting after post prevents duplicate submissions using the "back" button but will not prevent a duplicate post if a user submits more than once in rapid succession. Typically when a Struts action is going to forward to a page that will post information the action will call Action.saveToken(HttpServletRequest). Struts will then automatically add the token to the form when the
First you need to inform in Struts-Config.xml file.
You need not create a BeanClass with setters and getters. Its automatically created.
So using this form is very easy but have performance costs... <FORM-BEANS><FORM-BEAN name="submitQstnForm" type="org.apache.struts.validator.DynaValidatorForm">form-property name="USER" type="java.lang.String"/>
Inside Action Class you can access like this:
DynaValidatorForm submitQstnForm = (DynaValidatorForm)form;
String user = submitQstnForm.get("USER").toString();
String mail = submitQstnForm.get("MAIL").toString();
//Now play with the data.
Connection Pooling in Struts :
In struts-config.xml file data sources tag is there? you can configure connection pool from that xml file and you can create the connection as below.
<set-property property="driverClassName" value="com.mysql.jdbc.Driver" />
<set-property property="url" value="jdbc:mysql://localhost/DBNAME" />
<set-property property="username" value="" />
<set-property property="password" value="abcdefgh" />
<set-property property="maxActive" value="20" />
<set-property property="maxWait" value="5000" />
<set-property property="defaultAutoCommit" value="false" />
<set-property property="defaultReadOnly" value="false" />
...//Here Other Struts Configuration Tags...
In the above file the default values comes with this file was maxActive 20.
You can set the values here as per your network traffic on your server?
Here totally 20 connection objects will be active in the pool and 5000 (5 seconds ) will be the time to wait for a connection object. You can set number of maxIdle connections also.
CODE : in your Action Class execute method or any other class you can create the connection object like this.
//Just declare the data source and connection objects;
javax.sql.DataSource dataSource = null;
java.sql.Connection myConnection = null;
//Just by using the following 2 lines of Code you can create a connection //object from the data source by using the concept of connection pooling.
dataSource = getDataSource(request);
myConnection = dataSource.getConnection();
You can also refer to EJB Instance Pooling...
How do you configure data source in Tomcat ?
How do you configure data source in WebLogic ?
How do you configure data source in JBoss ?
How do you configure data source in WebSphere ?
Hibernate is a tool which hides the data accessing logic. Using Hibernate without writing a single SQL Query we can access the data from the database. Even if you have no knowledge of SQL, you can access data.
If the project size is very large, writing DAO's needs an expert level JDBC Programmer who can write minimal code with standards. But with out knowing all these we can use hibernate which will generate standard code to access data.
Hibernate is an ORM tool. Object Relational Mapping tool. We can store an employee object directly into the database using setters and getters.
Hibernate is a complete alternative for JDBC. If you want you can write SQL queries on your own but hibernate's main purpose is it will write SQL queries at background for you.
Hibernate is a pure Java object-relational mapping (ORM) and persistence framework that allows you to map plain old Java objects to relational database tables using (XML) configuration files. Its purpose is to relieve the developer from a significant amount of relational data persistence-related programming tasks.
The Spring Framework is an application framework and inversion of control container for the Java platform.
The framework's core features can be used by any Java application, but there are extensions for building web applications on top of the Java EE platform.
Plug-in: A hardware or software module that adds a specific feature or service to a larger system. The idea is that the new component simply plugs in to the existing system.
Ads By Google
© 2018 - JavaSpartans.com • All Rights Reserved