Java J2ee Struts Hibernate Spring Interview Questions Java J2ee Struts Hibernate Spring Interview Questions
238 Results; Time:0.177 Sec; Page : 1 ; Results From 1 to 10. Results Per Page

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

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

4. What is Hibernate ?

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.

5. What is Spring Framework ?

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.

6. What is a plug-in ?

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.

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

8. Can a single ActionClass be used by two different actions ?

9. Can you explain about Struts Control Flow ?

10. What are the similarities and differences between Struts Framework and Spring Framework ?

Java J2ee Struts Hibernate Spring Interview Questions
238 Results; Time:0.177 Sec; Page : 1 ; Results From 1 to 10. Results Per Page
Menu - - Java J2ee Struts Spring Hibernate Interview Questions - A home for your website
Ads By Google