Struts is a widely used framework for developing web applications. Struts is from jakarta open source team. Struts 2 more powerful than struts.

Custom Tags

  • html
  • Logic
  • bean
  • nested

Example code using the struts html tag

<%@ taglib uri=“../struts-html.tld” prefix=“html”%>
<html:form action=“”>
User: <html:text property=“userId”/>
Password: <html:password property=“password”/>
<html:submit value=“Submit”/>

Struts Configuration File

<struts-config>... <form-beans>
... </form-beans> ...



Login Page

<html:form action=“”>
User: <html:text property=“userId”/>
Password: <html:password property=“password”/>
<html:submit value=“Submit”/>


public LoginForm extends Action Form{
private String userId; //getter and setter methods for these.
private String password;
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request){
ActionErrors errors = new ActionErrors();
if(userId == null || "".equals(userId)){
ActionError error = new ActionError("error.login.userRequired");
} //other validations
return errors;


<exception key=“error.nodatabase” path=“/error.jsp” type=“com.sample.struts.DatabaseException”/>
<forward name=“sessiontimeout” path=“/sessiontimeout.jsp”/>
<action path=“\login" scope="request" validate="true" input="/login.jsp">
<forward path=“/homepage.jsp"/>
<forward path="/login.jsp"/>
<exception key="error.invalidlogin" path="/login.jsp" scope="request"/>
<message-resources name=“application”/>

Action Class

Class LoginAction extends Action{
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response){
LoginForm loginForm = ( LoginForm) form;
String userId = loginForm.getUserId
String password = loginForm.getPassword;
if(authenticate(userId, password){
return mapping.findForward(“success”);
return mapping.findForward(“failure")

More in Struts

Struts tiles
Advanced templating framework, that separates content from the layout

Struts validator framework
Declaratively configure validation routines without having to program validation logic

Multiple module support
Separate configuration files for different modules, allows for better organization of the components in the web application.

Advantages of Struts

  • Centralized file based configuration
  • Form beans automatically populated from request parameters, validation possible
  • Struts custom tags
  • Supports tiles, validator framework and internationalization(i18n).
  • Consistent use of MVC
READ  Struts Spring Integration