<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Java Interview Questions &#187; Struts Interview Questions</title>
	<atom:link href="http://www.bestjavainterviewquestions.com/category/struts-interview-questions/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bestjavainterviewquestions.com</link>
	<description>Java Interview Questions &#124; Core Java Interview Questions &#124; Advanced Java Interview Questions &#124; EJB Interview Questions &#124; J2EE Interview Questions &#124; Hibernate Interview Questions</description>
	<lastBuildDate>Fri, 03 Feb 2012 10:23:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Why ActionServlet is Singleton in struts framework?</title>
		<link>http://www.bestjavainterviewquestions.com/why-actionservlet-is-singleton-in-struts-framework/</link>
		<comments>http://www.bestjavainterviewquestions.com/why-actionservlet-is-singleton-in-struts-framework/#comments</comments>
		<pubDate>Thu, 07 Apr 2011 13:07:41 +0000</pubDate>
		<dc:creator>Ramakrishna</dc:creator>
				<category><![CDATA[Struts Interview Questions]]></category>
		<category><![CDATA[actionservlet]]></category>
		<category><![CDATA[actionservlet class]]></category>
		<category><![CDATA[actionservlet controller]]></category>
		<category><![CDATA[struts framework]]></category>

		<guid isPermaLink="false">http://www.bestjavainterviewquestions.com/?p=635</guid>
		<description><![CDATA[actionservlet class ,struts framework,web.xml]]></description>
			<content:encoded><![CDATA[<div id="_mcePaste">org.apache.struts.action.ActionServlet in the web.xml configuration file must defined as</div>
<div id="_mcePaste">ActionServlet provided by the struts Framework is a built-in servlet. ActionServlet nothing but a controller.</div>
<div id="_mcePaste">It has the following inbuilt design patterns.</div>
<div id="_mcePaste">1 singleton designpatteren.</div>
<div id="_mcePaste">2.FrontController</div>
<div id="_mcePaste">3.ApplicationController</div>
<div id="_mcePaste">4.MVC</div>
<div id="_mcePaste">5.Data Transfer object/value object</div>
<div id="_mcePaste">6.Inversion of control/Dependency injection</div>
<div id="_mcePaste">ActionServlet take the multiple request but it creates single instance for that requests by using singleton design pattern.</div>
<div id="_mcePaste">Few servers likes weblogic violates single instance multiple threads principle of servlet programming.That means these servers that will create more than once object for a class in special situation. see here</div>
<div id="_mcePaste">To avoid this type of situations &amp; to follow servlet specifications, struts framework software developers have made built-in servlet called ActionServlet.</div>
<div id="_mcePaste">Note:</div>
<div id="_mcePaste">1. According to MVC principles, there should be only one servlet acting as controller and this servlet should have only one object.</div>
<div id="_mcePaste">2. Both the approaches have advantages &amp; disadvantages <img src='http://www.bestjavainterviewquestions.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </div>
<p>org.apache.struts.action.ActionServlet in the web.xml configuration file must defined as<br />
ActionServlet provided by the struts Framework is a built-in servlet. ActionServlet nothing but a controller.It has the following inbuilt design patterns.<br />
1 singleton designpatteren.</p>
<p>2.FrontController</p>
<p>3.ApplicationController</p>
<p>4.MVC</p>
<p>5.Data Transfer object/value object</p>
<p>6.Inversion of control/Dependency injection<br />
ActionServlet take the multiple request but it creates single instance for that requests by using singleton design pattern.<br />
Few servers likes weblogic violates single instance multiple threads principle of servlet programming.That means these servers that will create more than once object for a class in special situation. see hereTo avoid this type of situations &amp; to follow servlet specifications, struts framework software developers have made built-in servlet called ActionServlet.<br />
Note:</p>
<p>1. According to MVC principles, there should be only one servlet acting as controller and this servlet should have only one object.</p>
<p>2. Both the approaches have advantages &amp; disadvantages</p>
<h2  class="related_post_title">Random Posts</h2><ul class="related_post"><li>October 3, 2008 -- <a href="http://www.bestjavainterviewquestions.com/jsp-scriplets-and-templets/" title="Jsp Scriplets and Templets">Jsp Scriplets and Templets</a> (0)</li><li>October 3, 2008 -- <a href="http://www.bestjavainterviewquestions.com/explain-jsp-directives/" title="Explain Jsp Directives">Explain Jsp Directives</a> (0)</li><li>October 16, 2008 -- <a href="http://www.bestjavainterviewquestions.com/479/" title="What is Thread Safe Servlet">What is Thread Safe Servlet</a> (0)</li><li>September 30, 2008 -- <a href="http://www.bestjavainterviewquestions.com/define-precompile-of-jsp-page/" title="Define Precompile of Jsp page">Define Precompile of Jsp page</a> (0)</li><li>October 16, 2008 -- <a href="http://www.bestjavainterviewquestions.com/define-jsp/" title="Define JSP">Define JSP</a> (2)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.bestjavainterviewquestions.com/why-actionservlet-is-singleton-in-struts-framework/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Difference between errortag and message tag</title>
		<link>http://www.bestjavainterviewquestions.com/difference-between-errortag-and-message-tag/</link>
		<comments>http://www.bestjavainterviewquestions.com/difference-between-errortag-and-message-tag/#comments</comments>
		<pubDate>Sun, 05 Oct 2008 10:29:25 +0000</pubDate>
		<dc:creator>Ramakrishna</dc:creator>
				<category><![CDATA[Struts Interview Questions]]></category>
		<category><![CDATA[java actionerror and actionmessages]]></category>

		<guid isPermaLink="false">http://www.bestjavainterviewquestions.com/?p=457</guid>
		<description><![CDATA[Q) What is the difference between errorstag and message tag? Rep) Errorstag genereates the error for Ex: &#60;%@ taglib uri=&#8221;/tags/struts-html&#8221; prefix=&#8221;html&#8221; %&#62; O/P of rs.jsp &#60;/html:errors/&#62; When the errors tag is evaluated a list of error message will be generated based on the  ActionError objects available in ActionErrors object. while generating the list of errors [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Q) What is the difference between errorstag and message tag?</strong></p>
<p><strong>Rep) </strong>Errorstag genereates the error</p>
<p>for Ex:</p>
<p>&lt;%@ taglib uri=&#8221;/tags/struts-html&#8221; prefix=&#8221;html&#8221; %&gt;</p>
<p>O/P of rs.jsp</p>
<p>&lt;/html:errors/&gt;</p>
<p>When the errors tag is evaluated a list of error message will be generated based on the  ActionError objects available in ActionErrors object. while generating the list of errors the errors tag uses the message resources with the keys Errors.header,Errors.prefix,Errors.suffix and Errors.footer.</p>
<p>This forces us to use the html tags as part of the properties file which is not a good practice. As an alternative to the errors tag messages tag is provided to use themessage tag we need not provide the html tags in the properties file.</p>
<p><em><strong><span style="text-decoration: underline;">re.jsp </span></strong></em></p>
<p>&lt;%@ taglib uri=&#8221;/tags/struts-bean&#8221; prefix=&#8221;bean&#8221; %&gt;</p>
<p>&lt;html:messages id=&#8221;msg&#8221;&gt;</p>
<p>&lt;li&gt;&lt;bean:write name=&#8221;msg&#8221;/&gt;</p>
<p>&lt;li&gt;</p>
<p>&lt;/html:messages&gt;</p>
<p>&lt;/ul&gt;</p>
<p>preffering message will be better than using the error tag because it saves time errors tags</p>
<p>some messages recognize in the pro since which allows to make use of html tags</p>
<p>As an alternative for save errors method,save messages() method is provided as an alternative to action errors;ActionMessages&#8217; class is provided</p>
<p><span style="text-decoration: underline;"><strong>one.jsp :</strong></span><strong>- </strong></p>
<p>&lt;ul&gt;&lt;html:messages id=&#8221;msg&#8221; message=&#8221;true&#8221;&gt;</p>
<p>&lt;li&gt;&lt;bean:write name=&#8221;msg&#8221;/&gt;</p>
<p>&lt;li&gt;&lt;/html:message&gt;&lt;/ul&gt;</p>
<p>If we use ActionMessage objects in place of ActionError objects we must specify message=true in the message given(tag)</p>
<h2  class="related_post_title">Random Posts</h2><ul class="related_post"><li>December 17, 2008 -- <a href="http://www.bestjavainterviewquestions.com/define-static-keyword/" title="Define Static Keyword">Define Static Keyword</a> (0)</li><li>June 24, 2008 -- <a href="http://www.bestjavainterviewquestions.com/java-jdbc-questions/" title="Java-Jdbc Questions">Java-Jdbc Questions</a> (0)</li><li>September 20, 2008 -- <a href="http://www.bestjavainterviewquestions.com/define-session-hijacking-2/" title="Define Session Hijacking">Define Session Hijacking</a> (0)</li><li>July 12, 2008 -- <a href="http://www.bestjavainterviewquestions.com/hibernate-interview-questions/" title="Hibernate Interview Questions">Hibernate Interview Questions</a> (0)</li><li>February 15, 2009 -- <a href="http://www.bestjavainterviewquestions.com/services-provided-by-ejb-container/" title="Services Provided by EJB Container">Services Provided by EJB Container</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.bestjavainterviewquestions.com/difference-between-errortag-and-message-tag/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>STRUTS Interview Questions</title>
		<link>http://www.bestjavainterviewquestions.com/struts-interview-questions/</link>
		<comments>http://www.bestjavainterviewquestions.com/struts-interview-questions/#comments</comments>
		<pubDate>Mon, 07 Jul 2008 17:14:25 +0000</pubDate>
		<dc:creator>Ramakrishna</dc:creator>
				<category><![CDATA[Struts Interview Questions]]></category>

		<guid isPermaLink="false">http://www.bestjavainterviewquestions.com/?p=42</guid>
		<description><![CDATA[Q) What is the advantage of DispatchAction class? A) Using DispatchAction class you can overcome writing one Action class for one business entity. Instead you can write multiple business entities in one Action class and call the business  method that is required by the application. Q) Can you write your own method in Action class [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Q) What is the advantage of DispatchAction class?<br />
A) </strong>Using DispatchAction class you can overcome writing one Action class for one business entity. Instead you can write multiple business entities in one Action class and call the business  method that is required by the application.<br />
<strong><br />
Q) Can you write your own method in Action class other than execute() and call that user method directly?<br />
A)</strong> Yes, We can create any number of methods in Action class and instruct the action tag in struts-config.xml file to call that user method. This is possible by using DispatchAction class. A sample code would look like this</p>
<p>public class StudentAction extends DispatchAction<br />
{<br />
public ActionForward create(ActionMapping mapping, ActionForm form,<br />
HttpServletRequest req,<br />
HttpServletResponse res) throws Exception<br />
{<br />
return something;<br />
}<br />
public ActionForward read(ActionMapping mapping, ActionForm form,<br />
HttpServletRequest req,<br />
HttpServletResponse res) throws Exception<br />
{<br />
return something;<br />
}<br />
public ActionForward update(ActionMapping mapping, ActionForm form,<br />
HttpServletRequest req,<br />
HttpServletResponse res) throws Exception<br />
{<br />
return something;<br />
}</p>
<p>}<br />
In the above Action class if the user wants to call any method, he would do something like this in my struts-config.xml file<br />
&lt;action path=&#8221;/somePage&#8221;<br />
type=&#8221;StudentAction&#8221;<br />
name=&#8221;studentForm&#8221;<br />
&lt;b&gt;parameter=&#8221;methodToCall&#8221;&lt;/b&gt;<br />
scope=&#8221;request&#8221;<br />
validate=&#8221;true&#8221;<br />
input=&#8221;/student.jsp&#8221;&gt;</p>
<p>&lt;forward name=&#8221;success&#8221; path=&#8221;/success.jsp&#8221;/&gt;<br />
&lt;/action&gt;<br />
In this configuration file the value of the parameter methodToCall determines the method in the StudentAction class to be invoked. For example, the JSP from which you are calling this action, can set the methodToCall parameter to any of the methods it wants to.<br />
<strong><br />
Q) How you will enable front-end validation based on the xml in validation.xml?<br />
A) </strong>The &lt;html:javascript&gt; tag to allow front-end validation based on the xml in validation.xml. For example the code:<br />
&lt;html:javascript formName=&#8221;logonForm&#8221; dynamicJavascript=&#8221;true&#8221; staticJavascript=&#8221;true&#8221; /&gt; generates the client side java script for the form &#8220;logonForm&#8221; as defined in the validation.xml file. The &lt;html:javascript&gt; when added in the jsp file generates the client site validation script.</p>
<p><strong>Q) What happens when the user has not provided required information that is needed by the struts validator framework? Explain how struts handles to display the validation messages?<br />
A)</strong> When the user has not provided any required information, the validation messages are displayed to the user and this block of code does this job.</p>
<p>&lt;logic:messagesPresent&gt;<br />
&lt;bean:message key=&#8221;errors.header.login&#8221;/&gt;<br />
&lt;ul&gt;<br />
&lt;html:messages id=&#8221;error&#8221;&gt;<br />
&lt;li&gt;&lt;bean:write name=&#8221;error&#8221;/&gt;&lt;/li&gt;<br />
&lt;/html:messages&gt;<br />
&lt;/ul&gt;&lt;hr /&gt;<br />
&lt;/logic:messagesPresent&gt;<br />
<strong><br />
Q) Brief on how struts validation is working  ?<br />
A)</strong> Struts uses 2 XML files to validate the user form. validator-rules.xml and validation.xml  files. The validator-rules.xml defines a set of standard validations and these validations  are used in validation.xml file.<br />
Generally the rules defined in validator-rules.xml file are typical java class files that does the validation in the backend.<br />
<strong><br />
Q) Explain about ActionForm class??<br />
A) </strong>ActionForm class defines get and set methods for information provided by the client in the  HTML form. It has reset (for reseting the defined variables to its initital state) and  validate method for validating the user input.</p>
<p><strong>Q) Explain about Action Class  ??<br />
A) </strong>The Action Class is part of the Model and is a wrapper around the business logic. The purpose of Action Class is to translate the HttpServletRequest to the business logic. To  use the Action, we need to Subclass and overwrite the execute() method. In the Action  Class all the database/business processing are done. It is advisable to perform all the   database related stuffs in the Action Class. The ActionServlet (command) passes the  parameterize class to Action Form using the execute() method. The return type of the  execute method is ActionForward which is used by the Struts Framework to forward the request  to the file as per the value of the returned ActionForward object.<br />
<strong><br />
Q) Do you write an ActionForm class for every form that you need to process?<br />
A) </strong>No, I define DynaValidatorForm as this class takes care of defining get/set methods and doing the validation for me. And I need to define this class in struts-config.xml file. An e.g. would be</p>
<p>&lt;form-beans&gt;<br />
&lt;form-bean name=&#8221;categoryForm&#8221; type=&#8221;org.apache.struts.validator.DynaValidatorForm&#8221;&gt;<br />
&lt;form-property name=&#8221;category&#8221; type=&#8221;java.lang.String&#8221;/&gt;<br />
&lt;/form-bean&gt;</p>
<p>&lt;/form-beans&gt;<br />
<strong><br />
Q) How would struts handle &#8220;messages&#8221; required for the application?<br />
A) </strong>Messages are defined in a .properties file as name value pairs. To make these messages available to the application, you need to place the .properties file in WEB-INF/classes  folder. And define the following tag in struts-config.xml file</p>
<p>&lt;message-resources parameter=&#8221;ApplicationResources&#8221; /&gt;<br />
And in order to display a message in a jsp you would use<br />
&lt;bean:message key=&#8221;title.mytitle&#8221;/&gt;</p>
<p><strong>Q) What is the name of the XML file which handles requests and gives responses? And acts as a controller?<br />
A) </strong><br />
struts-config.xml file<br />
<strong><br />
Q) Explain about ActionServlet in Apache Struts  ??<br />
A)</strong> ActionServlet acts as a controller in Struts. There can be only one ActionServlet defined<br />
for a context. ActionServlet is defined in web.xml file of a context e.g. WEB-INF/web.xml.<br />
Can I have more than one struts-config.xml file?<br />
Yes. A sample configuration in web.xml file would look like this<br />
&lt;servlet&gt;<br />
&lt;servlet-name&gt;action&lt;/servlet-name&gt;<br />
&lt;servlet-class&gt;org.apache.struts.action.ActionServlet&lt;/servlet-class&gt;<br />
&lt;init-param&gt;<br />
&lt;param-name&gt;config&lt;/param-name&gt;<br />
&lt;param-value&gt;/WEB-INF/struts-config.xml&lt;/param-value&gt;<br />
&lt;/init-param&gt;<br />
&lt;!&#8211; module configurations &#8211;&gt;<br />
&lt;init-param&gt;<br />
&lt;param-name&gt;config/exercise&lt;/param-name&gt;<br />
&lt;param-value&gt;/WEB-INF/exercise/struts-config.xml&lt;/param-value&gt;<br />
&lt;/init-param&gt;<br />
&lt;init-param&gt;<br />
&lt;param-name&gt;config/upload&lt;/param-name&gt;<br />
&lt;param-value&gt;/WEB-INF/upload/struts-config.xml&lt;/param-value&gt;<br />
&lt;/init-param&gt;<br />
&lt;/servlet&gt;<br />
<strong><br />
Q) What is Struts Validator Framework?<br />
A)</strong> Struts Framework provides the functionality to validate the form data. It can be use to validate the data on the users browser as well as on the server side. Struts Framework emits  the java scripts and it can be used to validate the form data on the client browser. Server side  validation of form can be accomplished by sub classing your From Bean with DynaValidatorForm class.</p>
<p><strong>Q) What is the role of ActioMapping object in Struts Action class?<br />
A) </strong>An ActionMapping knows about the mapping of a particular request to an instance of a particular Action class.<br />
<strong><br />
Q) What happens internally when actionMappings.findForward(&#8220;target&#8221;) method is called in Action class. ?<br />
A)</strong> actionMappings.findForward(&#8220;target&#8221;) method returns ActionForward object. An ActionForward represents a destination to  which the controller, RequestProcessor, might be directed to perform a RequestDispatcher.forward or  HttpServletResponse.sendRedirect to, as a result of processing activities of an Action class.</p>
<p><strong>Q) Expalin JSP,Servlet Combination VS Struts Which is better and how?<br />
A) </strong>Struts is a framework based on Model-View-Controller (MVC) design paradigm. The Model represents the business or database code, the View represents the page design code, and the Controller represents the navigational code. The Struts framework is designed to help developers create web applications that utilize a MVC architecture. Struts framework internally uses Servlet Technology for processing the request and response.<br />
Sun Microsystems has provided the JSP / Servlet API specifications, and its the web server or application server vendor who implements the logic for the API.</p>
<p><strong>Q) Explain ActionForward against JSP:forward  ?<br />
A)</strong> jsp:forward is part of JSTL and will be used in JSP pages. It internally uses RequestDispatcher to forward the request to new jsp or servlet page .<br />
ActionForward is part of Struts framework and is used in Action class. It internally uses RequestDispatcher to forward the request to ActionServlet.</p>
<h2  class="related_post_title">Random Posts</h2><ul class="related_post"><li>September 8, 2008 -- <a href="http://www.bestjavainterviewquestions.com/servlet-session-examples/" title="Servlets Session Examples">Servlets Session Examples</a> (0)</li><li>October 5, 2008 -- <a href="http://www.bestjavainterviewquestions.com/difference-between-errortag-and-message-tag/" title="Difference between errortag and message tag">Difference between errortag and message tag</a> (0)</li><li>September 2, 2008 -- <a href="http://www.bestjavainterviewquestions.com/explain-session-destroy-in-servlets/" title="Explain session destroy in Servlets">Explain session destroy in Servlets</a> (0)</li><li>December 10, 2008 -- <a href="http://www.bestjavainterviewquestions.com/what-is-event-delegation-model/" title="What is Event Delegation Model">What is Event Delegation Model</a> (0)</li><li>August 10, 2008 -- <a href="http://www.bestjavainterviewquestions.com/example-programs-of-lifecycle-of-servlets/" title="Example programs of lifecycle of servlets">Example programs of lifecycle of servlets</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.bestjavainterviewquestions.com/struts-interview-questions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

