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
Its automaticlally done by struts, for more info refer "Struts Token Feature Concept"
This can be done by using Struts Token Feature.
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 ?
We can combine some couple of Actions into a module and we can create a seperate struts configuration file in the struts web application. To do that we need to inform the web container through web.xml file init param Tag as follows.
Avoid double clicks. save the state of the request object. Its easily done by struts, for more info refer "Struts Token Feature Concept"
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.
Because the designers want to remind us of the invisible underpinnings that hold up our houses, buildings, bridges, and ourselves when we are on stilts. This excellent description of Struts reflect the role the Struts plays in developing web applications.
ApplicationResources.properties or MessageResources.properties struts-config.xml tiles-defs.xml validation.xml validation-rules.xml
If a single thing appears in many forms then it is called as Polymorphism.In real-time Phosphorous exhibits polimorphism like Green Phosphorous and RedPhosphorous...
In realtime we can say the same International Credit or Debit Card will show polymorphism...If you use it in india it will give you rupees from ATM, If you use it US, it will give you dollars...
If we implement a web application with Struts I18n feature then a same web site will show different linguistic content content depending on the browser locale of the user.
In Java, method over loading and method overriding both will comes under dynamic polymorphism...
Ads By Google
© 2018 - JavaSpartans.com • All Rights Reserved