JavaSpartans
Java J2ee Struts Hibernate Spring Interview Questions Java J2ee Struts Hibernate Spring Interview Questions
1 2 3 4 5    Next

1. What do you know about Struts Token Feature ?

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 tag is rendered. When the post occurs the action should perform an Action.isValidToken(HttpServletRequest, true) to verify and invalidate the token. Any succeeding posts with the token will be cause isValidToken() to return false. I typically call Action.resetToken(HttpServletRequest) in any action that forwards to pages that will not alter state (session, db, ...).
We can write these methods inside Our Action Classes execte() method.The use of token in Struts is to prevent duplicate form submission due to the Back button. its NOT about resolving the double submit problem. After the user has logged out, none of the previous pages should even re-appear on the browsers. 2. Struts token is used to prevent double submits that could potentially occur after the user logs in and before the user logs out. You can prevent Refresh Button Problems. You can prevent going to back page using Back Button and submitting the same form. You can prevent just by entering the same URL and pressing enter button.


2. How do you prevent double form submission in Struts ?

Its automaticlally done by struts, for more info refer "Struts Token Feature Concept"


3. How do you handle double form submissions and duplicate posts in Struts ?

This can be done by using Struts Token Feature.


4. How do you configure DataSource in Struts ? How do you implement Connection Poooling in Struts ?

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.

<struts-config>
<data-sources>
<data-source type="org.apache.commons.dbcp.BasicDataSource">
<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" />  
data-source>
data-sources>
...//Here Other Struts Configuration Tags...
struts-config >

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 ?


5. Can we create multiple struts configuration files in Struts web application ? If possible how to do that ?

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.

<init-param>
            <param-name>config</param-name>
            <param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
            <param-name>config/modone</param-name>
            <param-value>/WEB-INF/struts-config-modone.xml</param-value>
</init-param>
<init-param>
            <param-name>config/modtwo</param-name>
            <param-value>/WEB-INF/struts-config-modtwo.xml</param-value>
</init-param>


6. How do you prevent double form submissions in JSP ?

Avoid double clicks. save the state of the request object. Its easily done by struts, for more info refer "Struts Token Feature Concept"


7. How do you implement DynaValidatorForm in Struts ?

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"/&gt;
..
</FORM-BEAN>import org.apache.struts.validator.DynaValidatorForm;
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.
</FORM-BEANS>


8. Why it called Struts?

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.


9. What configuration files are used in Struts?

ApplicationResources.properties or MessageResources.properties struts-config.xml tiles-defs.xml validation.xml validation-rules.xml


10. Give an example of Polymorphism ?

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...


Java J2ee Struts Hibernate Spring Interview Questions
1 2 3 4 5    Next
Menu - javaspartans.com - Java J2ee Struts Spring Hibernate Interview Questions
Hostens.com - A home for your website
Ads By Google