1.Create JSP page for User input
2.Add these 2 lines at the top of JSP
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
3.Write the action tag,which is reffers to "Formbean"
<html:form action="/login">
4.Create success,failure what ever depends upon our requirement
5.Creating an ActionForm Bean class for User input JSP(it conatins setter,getter methods)
6.add bean declaration to the struts-config.xml file
<form-beans>
<form-bean name="LoginForm" type="com.myapp.struts.LoginForm" />
</form-beans>
7.Creating an Action Class& make sure that the following action entry is added to the struts-config.xml file
<action-mappings>
<action name="LoginForm" path="/login" scope="request" type="com.myapp.struts.LoginAction" validate="false"/>
<action path="/Welcome" forward="/welcomeStruts.jsp"/>
</action-mappings>
9.Implement ActionForward execute(-,-,-,-)method
10.return return mapping.findForward("ur wish");
11.Setting Up an Error Message
private String error;
public void setError()
{
this.error ="<span style='color:red'>Please provide valid entries for both fields</span>";
}
12.Adding forward Entries to struts-config.xml
<action name="LoginForm" path="/login" scope="request" type="com.myapp.struts.LoginAction" validate="false">
<forward name="success" path="/WEB-INF/success.jsp"/>
<forward name="failure" path="/login.jsp"/>
</action>
13.Configuring and Running the Application
In the Projects window, double-click the web.xml deployment descriptor. The tabs listed along the top of the Source Editor provide you with an interface to the web.xml file. Click on the Pages tab. In the Welcome Files field, enter login.jsp.
14.Attaching a Stylesheet
Add a simple stylesheet to the project. One easy way to do this is by saving this sample stylesheet to your computer. Copy the file (Ctrl-C), then in the IDE, select the Web Pages node in the Projects window and press Ctrl-V). The file is added to your project.
Link the stylesheet to your JSP pages by adding a reference between the <head> tags of both login.jsp and success.jsp:
<link rel="stylesheet" type="text/css" href="stylesheet.css">
2.Add these 2 lines at the top of JSP
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
3.Write the action tag,which is reffers to "Formbean"
<html:form action="/login">
4.Create success,failure what ever depends upon our requirement
5.Creating an ActionForm Bean class for User input JSP(it conatins setter,getter methods)
6.add bean declaration to the struts-config.xml file
<form-beans>
<form-bean name="LoginForm" type="com.myapp.struts.LoginForm" />
</form-beans>
7.Creating an Action Class& make sure that the following action entry is added to the struts-config.xml file
<action-mappings>
<action name="LoginForm" path="/login" scope="request" type="com.myapp.struts.LoginAction" validate="false"/>
<action path="/Welcome" forward="/welcomeStruts.jsp"/>
</action-mappings>
9.Implement ActionForward execute(-,-,-,-)method
10.return return mapping.findForward("ur wish");
11.Setting Up an Error Message
private String error;
public void setError()
{
this.error ="<span style='color:red'>Please provide valid entries for both fields</span>";
}
12.Adding forward Entries to struts-config.xml
<action name="LoginForm" path="/login" scope="request" type="com.myapp.struts.LoginAction" validate="false">
<forward name="success" path="/WEB-INF/success.jsp"/>
<forward name="failure" path="/login.jsp"/>
</action>
13.Configuring and Running the Application
In the Projects window, double-click the web.xml deployment descriptor. The tabs listed along the top of the Source Editor provide you with an interface to the web.xml file. Click on the Pages tab. In the Welcome Files field, enter login.jsp.
14.Attaching a Stylesheet
Add a simple stylesheet to the project. One easy way to do this is by saving this sample stylesheet to your computer. Copy the file (Ctrl-C), then in the IDE, select the Web Pages node in the Projects window and press Ctrl-V). The file is added to your project.
Link the stylesheet to your JSP pages by adding a reference between the <head> tags of both login.jsp and success.jsp:
<link rel="stylesheet" type="text/css" href="stylesheet.css">
Dangerous:
- The Property names in the JSP Form & ActionForm Variables Must be Same!! Other wise Error will Thrown....
- Don't put name & property with same values.It returns Error
Ex: <html:text name="uname" property="uname" > </html:text> ERROR
javax.servlet.ServletException: javax.servlet.jsp.JspException:
Cannot find bean: "uname" in any scope