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

About the Author

author image
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

avatar
77 Comment threads
26 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
81 Comment authors
H KCithan SelvanilePritam SanjoreMANISH KUMAR Recent comment authors
newest oldest most voted
Felix Thomas
Guest
Felix Thomas

Require one urgent help. If i implement tiles with struts2 in the following order
–header.jsp
–my body content goes here(For eg. addCustomer.jsp)
–footer.jsp

when i click on any menu the page will be getting loaded as mentioned above. However, if i do the server side validation on the page(body) when the input is returned by struts(ie., not a valid input value) my page layout of struts is not working. It is directly showing only the body(addCustomer.jsp) with no header and no footer. Any help would be appreciated.

kiranmayi
Guest
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

Hui Zhou
Guest
Hui Zhou

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

swathi
Guest
swathi

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

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

Jerson
Guest
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

Jerson
Guest
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

swathi
Guest
swathi

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

parimala
Guest
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.

Joel
Guest
Joel

Muchas Gracias! 🙂

Source codes
Guest
Source codes

Great nice clean site. Thanks you very much

Royal
Guest
Royal

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

Manu
Guest
Manu

Please post STRUTS 2 validation tutorial.

Thanks

?aban Uluta?
Guest
?aban Uluta?

Hi Mkyong,
Great work, thanks.

Raja
Guest
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…

mkyong fan
Guest
mkyong fan

Hello, Mkyong

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

thank you

Priyanka
Guest
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… Read more »

trackback
best struts tutorials | Java best practice

[…]  Struts 2 Tutorial – […]

Mahanth
Guest
Mahanth

Hi mkYong,

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

ogott
Guest
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

Tamil
Guest
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… Read more »

Mohammad Faiz
Guest
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

Danny Mathew
Guest
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….

saira
Guest
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.

Karthik
Guest
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.

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

shaswat
Guest
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

Ravi Saini
Guest
Ravi Saini

hi Sir..

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

manish gupta
Guest
manish gupta

MKyong

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

Thanks
Manish

vivek
Guest
vivek

this one is nice for beginners