Struts Tutorial

Struts 1.x is the most famous, classic and proven Model-View-Contraller (MVC) framework. Often times, you will listen something like, meaningless to learn Struts 1.x, it’s a dead framework. However, with the huge success of Struts 1.x in early day, there are still hundreds of thousand companies are implemented Struts 1.x, and never consider upgrade, so the Struts 1.x is still causing many maintainability.
Struts 1.x is a complete web framework, provides complete web form components, validator, internalization, error handling, tiles layout, low learning curve and easy to implement it. In this tutorials, it provides many step by step examples and explanations on using Struts 1.x MVC framework.
Happy learning Struts. :)
Struts Quick Start
Let’s go through a quick start to understand about the Struts 1.x framework.
- Struts hello world example
Go thought a hello world example to understand how Struts MVC work.
Struts Configuration
All stuffs about Struts configuration.
- Configure the Struts Tag Libraries
To use Struts, you have to configure the Struts tag libraries property, either in manual or automatic way. - Configure a welcome page in Struts
Configure a welcome page in Struts. - Multiple Struts configuration files
Mutiple Struts configuration files are required in large project environment, here’s an example to show how to configure the multiple Struts configuration file. - Struts configuration files in wildcards support
If your project is following certain standard file structure, wildcard is a useful feature to reduce the duplicated code in Struts configuration file.
Struts Action & ActionForm
Action and ActionForm implementation class.
- ForwardAction Example
Allow you to access the JSP class directly, without go through the controller class. - DispatchAction Example
Allow you to group all related functions into a single action class. - MappingDispatchAction Example
Same with DispatchAction, group similar functionality into a single action class but with different mechanism - DynaActionForm example
Allow you to create a virtual form bean declaratively to increase the development speed.
Struts Web Form Components
Struts has complete support for all standard web form components.
- TextBox example
Struts <html:text> textbox example. - Hidden value example
Struts <html:hidden> hidden value example. - Radio option example
Struts <html:radio> radio option example. - Drop down box example
Struts <html:select> drop down box example. - Check box example
Struts <html:checkbox> check box example. - File upload example
Struts <html:file> file upload example. - TextArea example
Struts <html:textarea> textaread example. - Rewrite example
Struts <html:rewrite> example, to render a requested URI, without create the hyperlink, useful for generate JavaScript and CSS file.
Struts Logic Tags
Struts comes with a lot logic tags to ease the bean component iteration or conditional processing.
- <logic:iterate> example
Struts tag to iterate over collections. - <logic:empty> <logic:notEmpty> example
Struts tag to check speficied property is null or zero-length String. - <logic:equal> <logic:notEqual> example
Struts tag to check speficied property is equal to a given value. - <logic:greaterThan> <logic:greaterEqual> <logic:lessThan> <logic:lessEqual> example
Struts conditional tag for comparing numbers. - <logic:match> <logic:notMatch> example
Struts tag to check the speficied property contains the given value as substring. - <logic:messagesPresent> <logic:messagesNotPresent> example
Struts tag to check the speficied message or error message exists on the current request. - <logic:present> <logic:notPresent> example
Struts tag to check the speficied given object or property is exists in the current request.
Struts Error and Logging
Exception handling and error logging.
- <global-exception> custom exception handler
Struts <global-exception> to display the custom error page to user. - Struts + Log4j integration
Integrate Struts with Log4j logging framework to log the system exceptions and errors. - Handle 404 error in Struts
Handling classic 404 error page in Struts.
Struts localization
Struts has good support in internationalizing or localization.
- Struts internationalizing or localization example
A simple user login example, all messages and error messages are localized.
Struts Validator Framework
In Struts validator framework, it provides many generic methods (required, maxlength, minlength..) to validate the form components, it makes your validation code more standardize and easier to maintain.
- Struts validator example
A simple user registration form , and validate the username, password and email field with Struts validator.
Struts Tiles Framework
Struts tiles framework is a powerful layout framework, which is used to maintain a standard look of header, footer or menu details across all of your web pages.
- Struts Tiles framework example
A simple web application to demonstrate the use the Sturts tiles framework to change the header and footer page easily.
Struts Integrate with Other Frameworks
Anything about the Struts integration with others framework.
- Struts + Spring integration
Example to integrate the Struts with Spring framework. - Struts + Hibernate integration
Example to integrate the Struts with Hibernate framework. - Struts + Spring + Hibernate integration
Example to integrate the Struts with Spring and Hibernate framework. - Struts + Quartz scheduler integration
Example to integrate the Struts with Quartz framework. - Struts + Spring + Quartz scheduler integration
Example to integrate the Struts with Spring and Quartz framework.
Struts Misc
Others Struts examples.
- Download file from website example
How to download file from a website in Struts.
Struts Common Errors
Some Struts common error messages.
- The absolute uri: http://struts.apache.org/tags-bean cannot be resolved in either web.xml or the jar files deployed with this application
- java.lang.ClassNotFoundException: org.apache.struts.action.ForwardAction
- Cannot find message resources under key org.apache.struts.action.MESSAGE
- java.lang.NoClassDefFoundError : org/apache/commons/fileupload/FileUploadException
- java.lang.NoClassDefFoundError: org/apache/commons/io/output/DeferredFileOutputStream
- <global-exceptions> xml parsing exception
- NoSuchMethodError : Digester.parse(Ljava/net/URL;)Ljava/lang/Object

Hi Frnds,
I am looking for email functionality in java using JMS.
1)In which i need to send as html email template(image).
2)How/where to capture the mail that is send successfully or failed.
Waiting for your valuable reply ASAP. Thanks in advance.
very nice.
tyut
sir i am not able to upload an image in struts1.2. and to reteive it from database..
sir please help me out.
thanking you
regards
sharad srivastava
Thank you very much.
this blog is very help ful sir , i am saying thanks to you for maintaining this website and you are doing the servicing for the people who are struggle for resolving the technical problems……………….
thank you very much, for doing the service………………………..
Very nice website
Hi
I need client side form validation using javascript on struts(username and password should be start with same character)
I love your blog, extremely helpful for me (beginner), and easy to understand. THANK YOU SIR!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Hi Mkyong,
How to achieve singleThreadModel in struts .. please share your ideas
nice question victoria but single thread model was deprecated in struts ans as wellas servlets,,,,,,,
in struct 1.1 .. how will do.. any idea.. thanks in advance..
Sir,
How to Implement security or web container security for struts1.x based web Application.
please give a demo.
Thanks
Hi,
Thanks for all your efforts
I need a solutions for my problem. In my application there is a combination of last name and email id. When new users are trying to register. If user id and last name exist alredy. this shows a error message on top “You are already register, Please click on ID Reminder Link”. So i want a hyper link on this message to the reminder ID link.
How can i paste a link to other page in Struts error message
Hi Sir,
whenever i tried to import the zip.file or even making my own struts1 based project using the same pom.xml i am getting this exception
It did not happen while i make my project without maven means by simple impoerting all jar file manually.
Please help me…
Waiting for your Solved reply soon….
SEVERE: Servlet /StrutsExample threw load() exception
java.lang.ClassNotFoundException: org.apache.commons.digester.RuleSet
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1387)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233)
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2389)
at java.lang.Class.getConstructor0(Class.java:2699)
at java.lang.Class.newInstance0(Class.java:326)
at java.lang.Class.newInstance(Class.java:308)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1116)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:993)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4149)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4458)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:722)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:516)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:583)
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 org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
6 Apr, 2012 7:54:47 PM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8086
6 Apr, 2012 7:54:48 PM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
6 Apr, 2012 7:54:48 PM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/319 config=null
6 Apr, 2012 7:54:48 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 4256 ms
6 Apr, 2012 7:55:01 PM org.apache.catalina.core.StandardWrapperValve invoke
INFO: Servlet action is currently unavailable
i didnot find any blog of EJB 3.0. Could you please provide tthis Blog for us.
great maven !
what is maven?
what is the use of maven?
how can we use it?
maven is just like eclipse it is a IDE
thanks a lot to mkyong
a”> Java codes here
XML -
HTML - <pre lang="html4strict"
Helps slove to my work, great blog!
thank U so much !
Your blog’s very usefully ! ^_^
Thanks.
this error is coming when i am running the struts applciation please help .
org.apache.jasper.JasperException: java.lang.ClassCastException: org.apache.catalina.util.DefaultAnnotationProcessor cannot be cast to org.apache.AnnotationProcessor.
thank you,
dhananjay