Monday, July 23, 2012

1.0.Basic Struts Example


index.jsp

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD><TITLE>New Account Registration</TITLE></HEAD>
<BODY BGCOLOR="#FDF5E6">
<CENTER>
<H1>New Account Registration</H1>
<FORM ACTION="register1.do" METHOD="POST">
  Email address: <INPUT TYPE="TEXT" NAME="email"><BR>
  Password: <INPUT TYPE="PASSWORD" NAME="password"><BR>
  <INPUT TYPE="SUBMIT" VALUE="Sign in me!">
</FORM>
</CENTER>
</BODY></HTML>


\WEB-INF

web.xml


<web-app>
  <!-- Standard Action Servlet Configuration  -->
  <servlet>
    <servlet-name>action</servlet-name>
    <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
    <init-param>
      <param-name>config</param-name>
      <param-value>/WEB-INF/struts-config.xml</param-value>
    </init-param>
  </servlet>
  <!-- Standard Action Servlet Mapping -->
  <servlet-mapping>
    <servlet-name>action</servlet-name>
    <url-pattern>*.do</url-pattern>
  </servlet-mapping>
</web-app>

struts-config.xml

<struts-config>
  <form-beans>
    <form-bean name="userFormBean"
               type="coreservlets.UserFormBean"/>
  </form-beans>
      <global-forwards>
    <forward name="success" 
             path="/WEB-INF/results/confirm.jsp"/>
  </global-forwards>
    <action-mappings>
    <action path="/register1" 
            type="coreservlets.RegisterAction1"
name="userFormBean"
            scope="request">
<forward name="bad-password" 
               path="/WEB-INF/results/bad-password.jsp"/>
<forward name="bad-address" 
               path="/WEB-INF/results/bad-address.jsp"/>
    </action>
  </action-mappings>
</struts-config>

Note- struts.jar must be in /WEB-INF/lib



No comments:

Post a Comment