• Action,  ActionForm,  Interview Questions,  Learn Struts,  Struts 2

    Struts2, First “Hello World Application”

    In this tutorial we will see how to create a simpe Struts 2 Hello World Application. The following files are needed to create a Hello World Application. web.xml struts.xml HelloWorld.java index.jsp success.jsp web.xml is used to configure the servlet container properties of the hello world appliation. The filter and the filter-mapping elements are used to setup the Struts 2 FilterDispatcher. The filter is mapped to the URL pattern “/*“. This means all the incoming request that targets to the Struts 2 action will be handled by FilterDispatcher class. <filter><filter-name>struts2</filter-name><filter-class>org.apache.struts2.dispatcher.FilterDispatcher </filter-class></filter><filter-mapping><filter-name>struts2</filter-name><url-pattern>/*</url-pattern></filter-mapping><welcome-file-list><welcome-file>index.jsp</welcome-file></welcome-file-list> The gateway for our hello world application is index.jsp file. The index.jsp file should be mentioned in web.xml as shown…

  • Exceptions,  Learn Struts,  Struts 2

    Troubleshooting – Struts2 – java.lang.NoClassDefFoundError

    Description:The tomcat server started without starting the webapp saying Listner start error. I had JEE app with Spring2.5, Struts2 and Tomcat 5.x combination. Trace:java.lang.NoClassDefFoundError: ognl/ClassResolverat com.opensymphony.xwork2.util.OgnlValueStackFactory.createValueStack(OgnlValueStackFactory.java:14)at org.apache.struts2.views.jsp.TagUtils.getStack(TagUtils.java:55)at org.apache.struts2.views.jsp.StrutsBodyTagSupport.getStack(StrutsBodyTagSupport.java:52)at org.apache.struts2.views.jsp.ComponentTagSupport.doStartTag(ComponentTagSupport.java:49)at org.apache.jsp.index_jsp._jspx_meth_s_005fhead_005f0(index_jsp.java:156)at org.apache.jsp.index_jsp._jspService(index_jsp.java:77)at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)at … Cause:The class path given in bean tag may be having incorrect path errors.Or there are some extra bean definition in applicationContext.xml which is not valid.

    Comments Off on Troubleshooting – Struts2 – java.lang.NoClassDefFoundError
  • Learn Struts,  Struts 2,  Tiles Plug-in

    Struts2 Tiles with example

    Here is an example that shows how to create tiles in Struts2 using the struts2 tiles plugin. First step will be to change deployment descriptor first setup the tiles definition file: <context-param> <param-name>     org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG  </param-name> <param-value>/WEB-INF/tiles.xml</param-value> </context-param> Now Listener Configuration will look like below: <listener> <listener-class>    org.apache.struts2.tiles.StrutsTilesListener </listener-class> </listener>  Now web.xml file should look like as below: <?xml version="1.0" encoding="UTF-8"?>    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>Struts2 Tiles Example</display-name>   <context-param> <param-name>     org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG  </param-name> <param-value>/WEB-INF/tiles.xml</param-value> </context-param> <listener> <listener-class>  org.apache.struts2.tiles.StrutsTilesListener  </listener-class> </listener>   <filter> <filter-name>struts2</filter-name> <filter-class> org.apache.struts2.dispatcher.ng.filter. StrutsPrepareAndExecuteFilter </filter-class> </filter>   <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>   <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app> Here is the Tiles.xml configuration…

    Comments Off on Struts2 Tiles with example
  • Action,  ActionForm,  Interview Questions,  Learn Struts,  Struts 2

    Struts DynaActionForm

    DynaActionForm is specialized subclass of ActionForm that allows the creation of form beans with dynamic sets of properties, without requiring the developer to create a Java class for each type of form bean. DynaActionForm eliminates the need of FormBean class and now the form bean definition can be written into the struts-config.xml file. So, it makes the FormBean declarative and this helps the programmer to reduce the development time.

    Comments Off on Struts DynaActionForm
  • ActionForm,  Learn Struts,  Struts 2

    What is Globalforward and Forward in Struts?

    A Struts forward is an object that is returned by an action and has two fields: a name and a path. The path indicates where a request is to be forwarded and it is available to all actions. Difference between Forward and global forwardA forward can be local (for specific action) or global (available to any action). A forward can be global or local. A global forward is defined in a struts-config.xml file and redirect to a specified JSP page. A local forward is defined in a struts-config.xml file in an action mapping and is invoked when the action is invoked. Example for Global Forward<global-forwards>  <forward   name=”logoff”               path=”/Applogoff.do”/>  <forward   name=”logon”                path=”/Applogon.jsp”/> …

    Comments Off on What is Globalforward and Forward in Struts?
  • Exceptions,  Interview Questions,  Learn Struts,  Struts 1,  Struts 2

    org.apache.jasper.JasperException: Unable to read TLD “META-INF/tlds/struts-tiles.tld” from JAR file org.apache.jasper.JasperException: Failed to load or instantiate

    All of sudden scenarios come over where struts-tiles.xml or struts component missing from struts.jar and it is present into jar, it usually come under circumstances when migration of server took place. Issue description: org.apache.jasper.JasperException: Unable to read  TLD “META-INF/tlds/struts-tiles.tld” from JAR file <struts.jar> org.apache.jasper.JasperException: Failed to load or instantiate or files usually present struts.xml are not caught by application server at runtime. I would recommend you to please go through the following steps to resolve the issue: Step1: In case Application server is not able to render/called classes or xml and throw errors, it means two same classes or component come accross within two jars, same can be here as Tomcat and struts.jar…

    Comments Off on org.apache.jasper.JasperException: Unable to read TLD “META-INF/tlds/struts-tiles.tld” from JAR file org.apache.jasper.JasperException: Failed to load or instantiate
  • Action,  ActionForm,  Controler,  Learn Struts,  Model,  Struts 1.x,  Struts 2,  Struts Components,  Tiles Plug-in,  Validator Plug-in,  View

    What are the different components for struts application?

    Struts 1.x Framework have following components in its application: struts-config.xml ActionForm Bean View(JSP or ftl) Action Class Model (DAO,DTO classes) And may have following extensible component for Application: Validator.xml Validator class tiles-defs.xml Your comments give us opportunity to improve my blogs, so please comment.

    Comments Off on What are the different components for struts application?
  • Learn Struts,  Struts 1.x,  Struts 2

    Workflow for Struts application.

    LStruts Application follows MVC design pattern, and use below components to complete MVC design pattern: 1.) struts-Config.xml for vsersion 1.2(struts.xml for Struts 2)2.) ActionForm3.) Request Processor4.) web.xml5.) validator.xml6.) Action7.) JSP or View layer Above components are required to complete the Struts WorkFlow; Please find below the diagram for understanding an application workflow: Above Diagram illustrate the basic workflow of a struts application.

    Comments Off on Workflow for Struts application.
  • Interview Questions,  Learn Struts,  Struts 1,  Struts 2

    Interview Questions on struts 1 and struts 2

    The interview questions asked to me in my various interview, Please be prepared in case you are having one: 1.) What is difference between struts 1 and struts 2?2.) How is the MVC design pattern used in Struts framework?3.) What is ActionServlet?4.) What is RequestProcessor, and how to create your own RequestProcessor?5.) How you will make available any Message Resources Definitions file to the Struts Framework Environment?6.) Is Struts Thread safe?7.) What is workflow of Struts application?8.) How to use vo,dao and dto design patterns in struts framework?9.) Can we change location for struts-config.xml?10.) What are different types of Actions we have in Struts?11.) What is DynaActionForm, and what is…

    Comments Off on Interview Questions on struts 1 and struts 2
  • Action,  Controler,  Interview Questions,  Learn Struts,  Struts 1,  Struts 2,  Struts Components

    What is Action Class?

    An Action class in the struts application extends Struts ‘org.apache.struts.action.Action” Class. Action class acts as wrapper around the business logic and provides an inteface to the application’s Model layer. It acts as glue between the View and Model layer. It also transfers the data from the view layer to the specific business process layer and finally returns the procssed data from business layer to the view layer. An Action works as an adapter between the contents of an incoming HTTP request and the business logic that corresponds to it. Then the struts controller (ActionServlet) slects an appropriate Action and creates an instance if necessary, and finally calls execute method. To…

    Comments Off on What is Action Class?