• 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,  Validator Plug-in

    Struts2 Validation with Example

    Struts Validation is plugin is a mandatory and important for any web application, Validating is an important part of any web framework because it is one of the most painfully repetitive things to do.  In Struts 2, validation plugin is created with use of an < ActionClassName>-validation.xml file.  So, if we have an AddEmployee Action then we would create an AddEmployee-validation.xml file, Please find below one for AddEmployee: <!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0.2//EN" "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd"><validators> <field name="employeeId"> <field-validator type="requiredstring"> <message>Employee Name is required.</message> </field-validator> </field></validators>   It is *required to have both getters and setters for the field you are validating for.  As class AddEmployee will require both of…

    Comments Off on Struts2 Validation with Example
  • Learn Struts

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

    Comments Off on Struts2, First “Hello World Application”
  • 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
  • Learn Struts

    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?
  • Learn Struts

    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