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

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

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

<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" />  
...//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 ?

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

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


5. Can an ActionForm be used by two different Action classes ?

6. How many scopes are defined for a form bean or ActionForm in Struts framework?

Only 2 scopes are defined. They are request and session.

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

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

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

This can be done by using Struts Token Feature.

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

10. What configuration files are used in Struts? or struts-config.xml tiles-defs.xml validation.xml validation-rules.xml

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