Struts 2 Tutorial

Struts 2 tutorials

Apache Struts 2, another popular Java Model-View-Contraller (MVC) framework, combine of both successful WebWork and Struts 1.x web frameworks.

Apache Struts 2, is totally different with Struts 1, it’s core features are all implemented with interceptors, “value stack” concept, OGNL expression and Struts 2 tags to work around the application data, and many annotations and conventions to make this framework more simpler to use. In this tutorials, it provides many step by step examples and explanations on using Struts 2 MVC framework.

Happy learning Struts 2. :)

Struts 2 Quick Start

Struts 2 quick start example.

Struts 2 Configurations

Anything about Struts 2 configuration file.

Struts 2 Action & Form

Struts 2 Action and form data management.

Struts 2 Interceptors

Abything about Struts 2 interceptors.

Struts 2 UI Tags

Struts 2 UI tags, to render the HTML form and non-form componnets.

Struts 2 Control Tags

Struts 2 Control tags or Logic tags, help to do conditional processing, iterate, manipulate and display the data.

  • iterator tag example
    Struts 2 Iterator tag is used to iterate over a value, which can be any of java.util.Collection or java.util.Iterator.
  • if, elseIf, else tag example
    Struts 2 If, ElseIf and Else tags are used to perform basic condition checking.
  • append tag example
    Struts 2 append tag is used to combine few Iterators (created by List or Map) into a single Iterator.
  • generator tag example
    Struts 2 generator tag is used to generate an iterator based on the “val” attribute provided in the page.
  • merge tag example
    Struts 2 merge tag is used to merge few Iterators (created by List or Map) into a single Iterator.
  • sort tag example
    Struts 2 sort tag is used to sort a List using a java.util.Comparator.
  • subset tag example
    Struts 2 subset tag is used to output a subset or portion of an iterator elements.

Struts 2 Data Tags

Struts 2 Data tags, help to get the data from the ValueStack, or place the data into the ValusStack.

  • a tag example
    Struts 2 a tag is used to render a HTML “<a>” tag.
  • action tag example
    Struts 2 action tag is used to call action class directly from a JSP page.
  • bean tag example
    Struts 2 bean tag is used to instantiate a class in the JSP page.
  • date tag example
    Struts 2 date tag is used to format Date object in JSP page.
  • debug tag example
    Struts 2 debug tag is a very useful debugging tag to output the content of the “Value Stack” and also the “Stack Context” details in JSP page.
  • include tag example
    Struts 2 include tag is used to include JSP or HTML page directly into the current page.
  • i18n tag example
    Struts 2 i18n tag is used to get the message from any declared resource bundle, not just the resource bundle that associated with the current action.
  • param tag example
    Struts 2 param tag is used to parametrize other tags.
  • property tag example
    Struts 2 property tag is used to get the property value from a class, which will default to the current Action class.
  • push tag example
    Struts 2 push tag is used to push value to the top of stack, so that it can be access or reference easily.
  • set tag example
    Struts 2 set tag is used to assign a value to a variable in a specified scope (application, session, request, page, or action).
  • text tag example
    Struts 2 text tag is used to get the message from the resource bundle that’s bundle with the action class.
  • url tag example
    Struts 2 “url” tag is used to create an URL and output it as a text format.

Struts 2 Resource Bundle & Localization

Struts 2 resource bundle to support the web localization features (multiple language).

Struts 2 Theme

Struts 2 layout is designed by the “xhtml” theme, understand the Struts 2 theme concept is a “MUST”.

Struts 2 Integrate with Other Frameworks

Anything about the Struts 2 integration with others framework – Spring, Hibernate, Quartz, Log4j…

Struts 2 FAQ

Struts 2 FAQ.

Struts 2 Common Errors

Struts 2 common errors.

Struts 2 Reference

Tags :

About the Author

mkyong
Founder of Mkyong.com and HostingCompass.com, love Java and open source stuff. Follow him on Twitter, or befriend him on Facebook or Google Plus. If you like my tutorials, consider make a donation to these charities.

Comments

  • Nevil Parekh

    Please help me out……
    Error:::

    Feb 27, 2013 3:15:34 PM org.apache.catalina.core.AprLifecycleListener init
    INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files (x86)\Java\jre7\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files (x86)/Java/jre7/bin/client;C:/Program Files (x86)/Java/jre7/bin;C:/Program Files (x86)/Java/jre7/lib/i386;C:\oraclexe\app\oracle\product\10.2.0\server\bin;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x86;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x64;C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\90\Tools\binn\;D:\Applications\eclipse;;.
    Feb 27, 2013 3:15:34 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
    WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property ‘source’ to ‘org.eclipse.jst.jee.server:Struts_starter’ did not find a matching property.
    Feb 27, 2013 3:15:35 PM org.apache.coyote.AbstractProtocol init
    INFO: Initializing ProtocolHandler [“http-bio-8080″]
    Feb 27, 2013 3:15:35 PM org.apache.coyote.AbstractProtocol init
    INFO: Initializing ProtocolHandler [“ajp-bio-8009″]
    Feb 27, 2013 3:15:35 PM org.apache.catalina.startup.Catalina load
    INFO: Initialization processed in 1773 ms
    Feb 27, 2013 3:15:35 PM org.apache.catalina.core.StandardService startInternal
    INFO: Starting service Catalina
    Feb 27, 2013 3:15:35 PM org.apache.catalina.core.StandardEngine startInternal
    INFO: Starting Servlet Engine: Apache Tomcat/7.0.27
    Feb 27, 2013 3:15:41 PM com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
    INFO: Parsing configuration file [struts-default.xml]
    Feb 27, 2013 3:15:41 PM com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
    INFO: Parsing configuration file [struts-plugin.xml]
    Feb 27, 2013 3:15:41 PM com.opensymphony.xwork2.util.logging.commons.CommonsLogger error
    SEVERE: Dispatcher initialization failed
    Unable to load configuration. – bean – jar:file:/C:/Users/Lenovo/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/Struts_starter/WEB-INF/lib/struts2-gxp-plugin-2.3.4.1.jar!/struts-plugin.xml:8:162
    at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:69)
    at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:390)
    at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:437)
    at org.apache.struts2.dispatcher.ng.InitOperations.initDispatcher(InitOperations.java:74)
    at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.init(StrutsPrepareAndExecuteFilter.java:51)
    at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:277)
    at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:258)
    at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:382)
    at org.apache.catalina.core.ApplicationFilterConfig.(ApplicationFilterConfig.java:103)
    at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4638)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5294)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1566)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1556)
    at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    Caused by: Unable to load bean: type:org.apache.struts2.views.gxp.inject.InjectedObjectContainer class:org.apache.struts2.views.gxp.inject.InjectedObjectContainer – bean – jar:file:/C:/Users/Lenovo/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/Struts_starter/WEB-INF/lib/struts2-gxp-plugin-2.3.4.1.jar!/struts-plugin.xml:8:162
    at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:243)
    at org.apache.struts2.config.StrutsXmlConfigurationProvider.register(StrutsXmlConfigurationProvider.java:102)
    at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:210)
    at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:66)
    … 18 more
    Caused by: java.lang.ClassNotFoundException: org.apache.struts2.views.gxp.inject.InjectedObjectContainer
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1711)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1556)
    at com.opensymphony.xwork2.util.ClassLoaderUtil.loadClass(ClassLoaderUtil.java:152)
    at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:214)
    … 21 more

    Feb 27, 2013 3:15:41 PM org.apache.catalina.core.StandardContext filterStart
    SEVERE: Exception starting filter struts2
    Unable to load configuration. – bean – jar:file:/C:/Users/Lenovo/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/Struts_starter/WEB-INF/lib/struts2-gxp-plugin-2.3.4.1.jar!/struts-plugin.xml:8:162
    at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:450)
    at org.apache.struts2.dispatcher.ng.InitOperations.initDispatcher(InitOperations.java:74)
    at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.init(StrutsPrepareAndExecuteFilter.java:51)
    at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:277)
    at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:258)
    at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:382)
    at org.apache.catalina.core.ApplicationFilterConfig.(ApplicationFilterConfig.java:103)
    at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4638)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5294)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1566)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1556)
    at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    Caused by: Unable to load configuration. – bean – jar:file:/C:/Users/Lenovo/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/Struts_starter/WEB-INF/lib/struts2-gxp-plugin-2.3.4.1.jar!/struts-plugin.xml:8:162
    at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:69)
    at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:390)
    at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:437)
    … 16 more
    Caused by: Unable to load bean: type:org.apache.struts2.views.gxp.inject.InjectedObjectContainer class:org.apache.struts2.views.gxp.inject.InjectedObjectContainer – bean – jar:file:/C:/Users/Lenovo/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/Struts_starter/WEB-INF/lib/struts2-gxp-plugin-2.3.4.1.jar!/struts-plugin.xml:8:162
    at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:243)
    at org.apache.struts2.config.StrutsXmlConfigurationProvider.register(StrutsXmlConfigurationProvider.java:102)
    at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:210)
    at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:66)
    … 18 more
    Caused by: java.lang.ClassNotFoundException: org.apache.struts2.views.gxp.inject.InjectedObjectContainer
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1711)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1556)
    at com.opensymphony.xwork2.util.ClassLoaderUtil.loadClass(ClassLoaderUtil.java:152)
    at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:214)
    … 21 more

    Feb 27, 2013 3:15:41 PM org.apache.catalina.core.StandardContext startInternal
    SEVERE: Error filterStart
    Feb 27, 2013 3:15:41 PM org.apache.catalina.core.StandardContext startInternal
    SEVERE: Context [/Struts_starter] startup failed due to previous errors
    Feb 27, 2013 3:15:42 PM org.apache.coyote.AbstractProtocol start
    INFO: Starting ProtocolHandler [“http-bio-8080″]
    Feb 27, 2013 3:15:42 PM org.apache.coyote.AbstractProtocol start
    INFO: Starting ProtocolHandler [“ajp-bio-8009″]
    Feb 27, 2013 3:15:42 PM org.apache.catalina.startup.Catalina start
    INFO: Server startup in 6759 ms

  • IBM

    Dear All,

    Could you please share the src code, how to upload .csv file into database using core Java?
    I would appreciated if some one can help me in this regards.

    Regards,
    Prateek

  • http://www.arcadetemple.com/profile/view/365457.html Overseas qualified nurses visa

    I_m not that much of a internet reader to be honest but your sites really nice, keep it
    up! I’ll go ahead and bookmark your site to come back in the future. All the best

  • http://www.squidoo.com/fearofflyingtipsconquerfearofflying for beginners

    Oh my goodness! Amazing article dude! Many thanks, However I am having
    troubles with your RSS. I don’t understand why I can’t join it.

    Is there anyone else having identical RSS issues? Anyone who knows
    the solution can you kindly respond? Thanks!!

  • kamal gupta

    I am new to Struts 2.3. And Mkyong Tutorial are fantastic, these helpmed me a lot to learn quickly.

  • Dev

    Nice

  • nityananda

    Hi Sir
    As per your words you told when” There is no Action mapped for namespace / and action name showAjaxLoginCancelForm” will come type the actioename.action,but when will submit the page if this error will come then what we will do.

  • Pankaj Sharma

    I have been reading your tutorials for some days.
    You are truly awesome dude.I have been waiting when you will bring struts2
    with struts2-jquery tags.keep it up dude.

  • Dharmit

    hi..

    do you have any example regarding internationalization like if i m login with selecting “English” language then in my project i can write in my textfield in English. or if i m login with selecting “French” language then in my project i can write in my textfield only in french…

    Thanks.. :)

  • Raghotham

    Hi VP,
    I just wanted to check with you as to how i remove struts 1 and then start using struts 2…i tried the steps given but its not working..I have Java 6, i donno if i have installed it correctly..however when i type localhost:8080/ i am getting the tomcal welcome page..
    please let me know how to identify if struts, and tomcat is installed correctly..please help me.

    Raghotham

  • Junku

    Very Useful website….Got to understand struts and JSF better via the samples u’ve given

  • Nevil Parekh

    You have treasure of Java/J2ee examples.
    Your example of Struts 2.0 is awesome and very clear to understand….
    thanks a lot…….
    keep uploading ….
    Don’t stop……

  • Raghavendra
      please help me how to expand and collapse a tree when clicked on a root node. i'm using
    &lt;s:tree&gt; struts-tags taglib for it. Is it possible to achieve collapse and expansion using that taglib or is there any other plugin to achieve it...pleas help me out....its an urgent requirement for me..
  • Nirav

    Dear,
    my entire application depends on file upload where it uses struts 2 file upload as suggested all steps are followed and it’s working fine in my local(windows) environment while it’s not working in my test(linux) environment.
    it gives null pointer exception. File object is null in action class.
    Log trace :—-
    java.lang.NullPointerException at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:82) at com.fvrl.web.department.DepartmentAction.upload(DepartmentAction.java:104) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:452) at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:291) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:254) at com.fvrl.web.interceptors.SecurityManager.intercept(SecurityManager.java:61) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:133) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:207) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:207) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:190) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:94) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171) at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187) at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248) at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52) at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:498) at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77) at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161) at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231) at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317) at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195) at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:849) at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746) at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1045) at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228) at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137) at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104) at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90) at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79) at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54) at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59) at com.sun.grizzly.ContextTask.run(ContextTask.java:71) at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532) at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513) at java.lang.Thread.run(Thread.java:662)

  • Ashwini

    hello all,
    I want to know that how to build struts2 application using Ant build tool in eclipse. Please give me details of it.
    Thanks all.

  • saurabh
     package com.action;
     
    public class WelcomeUserAction
    {
      private String username;
     
    public String getUsername() {
    	return username;
    }
     
    public void setUsername(String username) {
    	this.username = username;
    }
      public String execute()
      {
    	  return &quot;SUCCESS&quot;;
      }
    }
     &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
    &lt;!DOCTYPE struts PUBLIC
    &quot;-//Apache Software Foundation//DTD Struts Configuration 2.0//EN&quot;
    &quot;http://struts.apache.org/dtds/struts-2.0.dtd&quot;&gt;
     
    &lt;struts&gt;
     
    	&lt;package name=&quot;user&quot; extends=&quot;struts-default&quot;&gt;
     
     
    		&lt;action name=&quot;Welcome&quot; class=&quot;com.action.WelcomeUserAction&quot;&gt;
    			&lt;result name=&quot;SUCCESS&quot;&gt;success.jsp&lt;/result&gt;
    		&lt;/action&gt;
    	&lt;/package&gt;
     
    &lt;/struts&gt;
     &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
    &lt;!DOCTYPE web-app PUBLIC
     &quot;-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN&quot;
     &quot;http://java.sun.com/dtd/web-app_2_3.dtd&quot; &gt;
     
    &lt;web-app&gt;
     
        &lt;filter&gt;
            &lt;filter-name&gt;struts2&lt;/filter-name&gt;
            &lt;filter-class&gt;org.apache.struts2.dispatcher.FilterDispatcher&lt;/filter-class&gt;
        &lt;/filter&gt;
        &lt;filter-mapping&gt;
            &lt;filter-name&gt;struts2&lt;/filter-name&gt;
            &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
        &lt;/filter-mapping&gt;
        &lt;welcome-file-list&gt;
            &lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt;
        &lt;/welcome-file-list&gt;
     
    &lt;/web-app&gt;
     &lt;%@ page language=&quot;java&quot; contentType=&quot;text/html; charset=ISO-8859-1&quot;
        pageEncoding=&quot;ISO-8859-1&quot;%&gt;
    &lt;%@ taglib prefix=&quot;s&quot; uri=&quot;/struts-tags&quot;%&gt;
    &lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot; &quot;http://www.w3.org/TR/html4/loose.dtd&quot;&gt;
    &lt;html&gt;
    &lt;head&gt;
    &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=ISO-8859-1&quot;&gt;
    &lt;title&gt;Learn Action Mapping&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
    &lt;s:form action=&quot;Welcome&quot;&gt;
    &lt;s:textfield name=&quot;username&quot; label=&quot;UserName&quot;&gt;&lt;/s:textfield&gt;
    &lt;s:password name=&quot;password&quot; label=&quot;Password&quot;&gt;&lt;/s:password&gt;
    &lt;s:submit&gt;&lt;/s:submit&gt;
    &lt;/s:form&gt;
    &lt;/body&gt;
    &lt;/html&gt;
    &lt;%@ page language=&quot;java&quot; contentType=&quot;text/html; charset=ISO-8859-1&quot;
        pageEncoding=&quot;ISO-8859-1&quot;%&gt;
     &lt;%@ taglib prefix=&quot;s&quot; uri=&quot;/struts-tags&quot;%&gt;
    &lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot; &quot;http://www.w3.org/TR/html4/loose.dtd&quot;&gt;
    &lt;html&gt;
    &lt;head&gt;
    &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=ISO-8859-1&quot;&gt;
    &lt;title&gt;Success Page&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
    &lt;h1&gt; Hello &lt;s:property value=&quot;username&quot; /&gt; &lt;/h1&gt;
    &lt;/body&gt;
    &lt;/html&gt;

    I m getting following error:

    WARNING: No configuration found for the specified action: ‘Welcome’ in namespace: ”. Form action defaulting to ‘action’ attribute’s literal value.

    pls guide me to resolve this error.

    • Pankaj Sharma

      I think you are not locating the configuration file struts.xml where it should be located.
      According to the architecture it should be along with the com package.

  • saurabh

    Hi I am learning Struts2. On clicking of Submit Button I am facing the following error:WARNING: No configuration found for the specified action: ‘Welcome’ in namespace: ”. Form action defaulting to ‘action’ attribute’s literal value.

    My Files are:

    Index.jsp
    ==============

    Learn Action Mapping

    success.jsp
    ==================

    Success Page

    Hello

    web.xml
    ============

    struts2
    org.apache.struts2.dispatcher.FilterDispatcher

    struts2
    /*

    index.jsp

    struts.xml
    ==================

    success.jsp

    Action Class
    ==============
    package com.action;

    public class WelcomeUserAction
    {
    private String username;

    public String getUsername() {
    return username;
    }

    public void setUsername(String username) {
    this.username = username;
    }
    public String execute()
    {
    return “SUCCESS”;
    }
    }

    pls guide me.I am not able to move forward because of this.

  • Ashish Gupta

    Thnx sir….
    For providing us tutorial of Struts 2…

  • Padmanaban

    Hello Mr MKYong,
    I am very new to struts2. I was trying to include a calender control in my JSP but could not. In .net framework the ready made calender control is available. I thought that the same way this struts2 framework also contain come sort of ready made controls which can be added to the JSPs. Plz help me to add the calender control to my JSP asap.

    thanks in anticipation
    K Padmanaban

  • Ranjit

    I need a tutorial on how to perform the CRUD operation in struts 2 alongwith where exactly should i put the connectivity code for connecting with the database

    • sampath

      Place all crud operations in one class and try to call those crud methods from action classes execute method….

  • sampath

    Dear Mr. MKYONG,
    This is sampath. I just want to share my problem. Im working with myeclipse 8.6 and im gettiing problem that it is not participating in the url path and showing action not found for namespace(/). I know it is taking default namespace but how to correct it. Your tutorials are excellent for beginers like me. You missed one of main concept Exception handling in struts2. I look forward to see your reply as well as exception handling tutorial….

    Regards
    Sampath

    • sampath

      At last i got an overview of namespaces but…. i changed my code to work with namespace…. How to get namespace in url path

  • vivek

    this one is nice for beginners

  • manish gupta

    MKyong

    Do we have pagination concept in struts 2? I am looking for this concept.

    Thanks
    Manish

  • http://www.gmail.com Ravi Saini

    hi Sir..

    How To Display All Records From mysql database to jsp table using struts2,
    help me soon………….

    • roshi

      dont try for what you dont know

  • shaswat

    Sir
    I’m a regular user of this website.I would like to request you for adding Jasper Report/ireport tutorials with the exsiting tutorials in this website.

    Looking forward to hear from you.

    Thanks with Regards
    Shaswat

  • Krish

    Hi i am really very very happy by seeing all this stuff at one place, thax for providing these many topics and if you provide flow & architecture with explanation of Struts2 so that it vill be more use full for me soo please please post that content..
    Thanx in Advance
    keep Posting….

  • Karthik

    Hi mkyong,

    Tutorial you provide are very easy to understand.
    So i request you to provide the same for Struts2 jQuery plugin.There are less documentation for this plugin and will be helpful for many developers.

    Thanks a lot for your tutorial, its very helpful.

  • saira

    hi

    i have a list of strings to be populated in a text area in struts2 but the strings are getting displayed within square braces and are comma seperated . how to display string without being enclosed in square braces and without commas???please reply as soon as possible.

  • Danny Mathew

    Hi,I tried the select tag.but its giving error that “The requested list key ‘searchEngine’ could not be resolved as a collection/array/map/enumeration/iterator type”

    I tried select tag from many sites.but all are showing this same error.is it due to not adding any plugins???

    please help me….

    • Mohammad Faiz

      you must be using struts2-jquery-tags before using struts2 select tag. And check if your getter and setter methods for the list to be populated in select tags are properly formed in java action class. Also check whether the list object is created before the result is displayed.

      public class SelectList extends ActionSupport
      {
          private List selectList;
          public List getSelectList()
          {
             return selectList;
          }
          
          public void setSelectList(List selectList)
          {
              this.selectList=selectList;
          }
      
          public String execute()
          {
              selectList=new ArrayList();
              selectList.add(new Customer(1,"Arif");
              selectList.add(new Customer(2,"Shahab");
              selectList.add(new Customer(3,"Shoeb");
              return "success";
          }
      }

      Note:- Annotation for json type is not included. This class is just to explain above
      expalnation.

    • Mohammad Faiz

      you must be using struts2-jquery-tags before using struts2 select tag. And check if your getter and setter methods for the list to be populated in select tags are properly formed in java action class. Also check whether the list object is created before the result is displayed.

  • Mohammad Faiz

    Hi,
    I have a problem regarding the use of grid in struts framework and i want to create hierarchical grid like in asp.net telerik tool using struts2 framework so if you have any idea about it please do share.
    Thank you

    • Mohammad Faiz

      I Got the answer on struts2-jquery-grid-showcase

  • Tamil

    Hi,

    Could you post a tutorial on using cookies with struts2?

    . We can read cookies using CookiesAware interface
    . We can write cookies to the response by response.addCookie(cookie)
    . But when it comes to re-direction from one host to another, the response looses the cookie informaiton, for example:

    I am accessing http://localhost/struts/mypage, I click on some link, and if I want to be redirected to http://somesite.net/strutstutorial.zip (say if its a file download), I miss the response information. when I look at live header, it says max-age is 0 and no cookie information is available.

    It would be really helpful if you could post a tutorial on this.

    Thanks

    • Tamil

      I fixed this issue;

      1. I found that the hostname I set in cookie domain mismatch
      2. cookie name value pair string had double quotes (we have to encode)
      3. some redundant value in cookie

      good luck

  • http://www.drachmatech.com ogott

    Hi,

    First off I think all your examples are really awesome!
    I noticed that you have a multi image upload example.
    What I was wondering is if you have an example with columns / rows with multi form fields?

    For example:
    Id First Name Last Name Age
    1 text box text box drop down
    2 text box text box drop down

    Most examples I’ve seen looking around have a edit link(with draw on single form), or delete link for each row.

    O

  • Mahanth

    Hi mkYong,

    tutorial is good.I want to know select box validation(which are populated by dojo using other action) in struts2.

  • Pingback: best struts tutorials | Java best practice()

  • Priyanka

    Hi,

    I have implemented most of my website application. However I faced a problem in using ajax. I wanted to get some details from my DB and show it at the front end using Ajax.

    I have written my ajax code (which works fine in other basic JSP application). The action that I send from my ajax code, calls the method of the action class as specified in struts.xml . new_jsp_page.jsp
    However on success it will call a new jsp page. So Ajax is not achieved.

    I have learnt from various sites and blogs that it is not possible to use ajax as used in normal JSP. We need to use some plugins like “dojo”

    Can you tell me if it is possible to achieve ajax without using these plugins?
    As of now I have created a jsp page which returns my content back to client. But I am forced to keep this jsp page out of my jsp folder as I need to restrict direct access of other jsp pages.

  • mkyong fan

    Hello, Mkyong

    Handling of Session in Struts 2 is not discussed (done through interceptors).

    thank you

  • Raja

    Hi mkyong..

    I appreciate your Struts2 tutorial. I am looking for simple example of custom tag which works and please explain in detail so it should work without any exception.

    appreciate it and thanks in advance…

  • ?aban Uluta?

    Hi Mkyong,
    Great work, thanks.

  • Manu

    Please post STRUTS 2 validation tutorial.

    Thanks

    • TJ

      Hi Mkyong,

      Have the same need for Struts 2 validation tutorial.

      Please help.

      Thanks

      TJ

  • http://www.csscolorcode.info Royal

    Kirmnani first you have to learn Java Script and then work on Struts

  • http://www.topsourcecode.com Source codes

    Great nice clean site. Thanks you very much

  • http://joeljil.wordpress.com Joel

    Muchas Gracias! :)

  • parimala

    hi mkyong,
    Could you please explain the struts frame work flow with clear diagrams, as you have specified for spring.
    because I am able to understand the spring frame work well, because it was mentioned with good diagrams.
    Could u please do the same for struts also.

    Thanks a lot for ur tutorial, its very helpful.

    • http://www.mkyong.com mkyong

      May i know which Spring’s article you’re referring? and which struts 2 article you’re feeling hard to understand? So that i can know which way of wring is good or bad :)

      Your inputs are appreciated. Thanks

      • parimala

        The spring framework mvc hello world example,
        located at http://www.mkyong.com/spring-mvc/spring-mvc-hello-world-example/
        has very good explanations like :
        work flow diagram,dependency etc were explained very clearly .

        but struts2 hello world example located at http://www.mkyong.com/struts2/struts-2-hello-world-example/
        does not have the explanation as in spring example.
        and one more thing, I never used Marven before, and you have explained your struts example with Marven, and spring example normally.
        Please explain the struts frame work with diagram.
        Thanks a lot

        • http://www.mkyong.com mkyong

          Really appreciated your invaluable feedback.

  • swathi

    hai im new to struts.im developing examples some how getting output,but im not getting upto the mark.can u help me…………

  • http://www.digitalprizm.com Jerson

    Hi mkyong,
    By the way I am using tomcat 6 as the webserver.
    I urgently need a solution…..Please help me

    Many Thanks and Regards,

    Jerson

    • http://www.digitalprizm.com Jerson

      awaiting your reply…Thanks in Advance

    • http://www.digitalprizm.com Jerson

      Hi ,
      Do you need more info about this…Please suggest me a solution

      Thnks

  • Jerson

    Hi mkyong,
    Please help me out.I have Struts2 Application which works fine when I run in localhost…Somehow I am failed to run using Virtual host name…It comes to stating login page after then it cannot execute my action classes….I am try to google for the solution but nothing works out…Please help me on this issue…..

    If My application can work in localhost I assume it will works for virtual host also…Please advice me on what can be the possible cause…

    Many Thanks and Regards,

    Jerson

  • live_for_java

    Hi
    My humble request is could you please post details about validations in struts 2. Please It will help most of your lovable visitors….

    from;
    Live_For_Java….

    • http://www.mkyong.com mkyong

      ya, it look like missing of Struts2 validation topic. Noted.

      • Live_for_java

        Hi mkyong..

        I like to thank you for your quick reply. I like to share something with you.your tutorial was most helpful for my recap.I kind request is pls post some details about web-service.My heartfull thanks for you.

        With regards;
        Live_for_java(Fan of your tutorial)

        • http://www.mkyong.com mkyong

          hi,
          Sorry, i’m just reply during free time :p, ya, one of the reason to write this site is for my own recap as well. Regards the web service, i haven’t finish yet, but you can refer to this URL for some of the articles http://www.mkyong.com/category/webservices/

          P.S fan? haha then consider join mkyong facebook fan page ~

          • Srishti

            Hi Mkyong, Your tutorials on Struts2 and Hibernate has been excellent .Thank you.
            But I need to ask one question on struts2 .

            I have a table in my database with fields(2 text boxes and 2 dropdown). And my jsp
            renders them correctly with respective values. Now What I want is whenever I add
            any field manually in my database how dynamically I can render it on my jsp using .
            Or U can point it as : the moment i add fields in my database it should get reflected in my UI (jsp).
            will using ajax help me????

  • swathi

    i want an example in struts2 which uses layout with out tiles

    • live_for_java

      Swathi you mean to say.. like templetes created using velocity,jsf.. etc…

  • Hui Zhou

    The tutorial is very easy to understand. Thanks for your contribution.

  • kiranmayi

    hi i am kiranmayi
    and i am developing a struts2 application that i want to to disable a when form loads and enable it when a link is clicks on it. can u give suggestion for it in how to write the code for it
    thanks and regards
    kiranmayi.v

    • mahendra

      Hello kiranmai,

      simply that one if you java script on ur application that will automatic works,.

      1.first you will right one java script method in ur jsp, in that method take that field id as refernce. and then right script for that ok.
      2. and the you declare that javascript method in onload function.

      • kiranmayi

        but i don’t know javascript.. :(

        • RK

          Kiranmayi,

          were you cdfi(chennai) student