(.........)
Action used to process data
UserAction.java
Import javax.servlet.http.httpservletRequest;
Import javax.servlet.http.httpservletResponse;
Import org.apache.struts.Action.Actionerro;
Import org.apache.struts.Action.actionform;
Import org.apache.struts.Action.actionForward;
Import org.apache.struts.action.actionmapping;
Import org.apache.struts.Actions.dispatchaction;
Public Class UseerAction Extends Dispatchction
{
Public ActionForward Execute (ActionMapping Mapping,
Actionform Form,
HTTPSERVLETREQUEST REQUEST,
Httpservletresponse response
Throws Exception
{
// Get page form information
Userform uform = (userform) Form;
/ / Get two data already submitted from the FROM
String Temp_str1 = uform.getstr1 ();
String Temp_str2 = uform.getstr2 ();
String Temp_stradd = TEMP_STR1 TEMP_STR1;
// put the result of the process in Form
uform.setstradd (TEMP_STRADD);
IF (! "". Equals (TEMP_STR1) &&! "" "" "Equals (Temp_Str2))
{
Return mapping.findforward ("ok");
}
Else
{
Return mapping.findforward ("ERR");
}
}
}
Hurry and see your results:
Start your Tomcat again, check your IE address:
Http: // localhost: 8080 / user / in.jsp
Tips you pay attention to a few places
1 in Struts-Config.xml
Type = "useeraction" Name = "Userform" ............ Execute UseerAction Userform Respectively In.JSP Java class uSerction.class "form-bean name =" userform "in Struts-config.xml ......... Userform "bean: Write name =" userform "in Success.jsp is Userform ... 2 in Struts-Config.xml with Java class Userform.class 3 See it in Form STR1, STR2, STRADD? In in .jsp and success.jsp, I found a blank white sauce four? / Span> I didn't understand? Oh, it turned out to be like this. In.jsp puts the value of Str1 and Str2 to the Form, then Aciton uses the GET method to take them out to process them, then put the result through the set method to the Form's stradd, and finally Success.jsp Take it out again to see you, is this? ? ! ! This is the process, and FORM has a "warehouse" that saves data (this saved is not permanent), Action has become a "factory" that handles and processes data. They jointly provide a full service of the data to the JSP page of the front desk. Ok, I have to say it, about this example, I have to tell you so much. Oh, forgot, embarrassed. Why do the Execute method in the action when the page is pressed when the "submit" type of the page is pressed. Haha, this is the advantage of struts! Is it "MYDOG" in this way to this method? Now you can't, I will tell you how you can tell you. .