STRUTS2 (iv) Action two configuration

Source: Internet
Author: User

First, the method parameter

Action

 Packagecom.pb.web.action; Public classhourseaction { PublicString Add () {System.out.println ("Perform the Add action! "); return"Success"; }     PublicString Update () {SYSTEM.OUT.PRINTLN ("Perform the update operation!" "); return"Success"; }     PublicString Delete () {System.out.println ("Perform the delete operation! "); return"Success"; }}

Struts.xml

<?xml version= "1.0" encoding= "UTF-8"? ><!DOCTYPE Struts public"-//apache software foundation//dtd Struts Configuration 2.3//en" "Http://struts.apache.org/dtds/struts-2.3.dtd" > <struts> <!--<constant name= "Struts.enable.DynamicMethodInvocation" value= "false"/> <constant na Me= "Struts.devmode" value= "false"/> < PackageName= "Default" namespace= "/"extends= "Struts-default" > <default-action-ref name= "index"/> <global-results> <result name= "error" &GT;/ERROR.JSP&LT;/RESULT&G        T </global-results> <global-exception-mappings> <exception-mapping exception= "Java.lang.Exc Eption "result=" error "/> </global-exception-mappings> <action name=" index "> <re Sult type= "Redirectaction" > <param name= "actionname" >HelloWorld</param> <p Aram Name= "namespace" >/example</param> </result> </action> </ Package> <include file= "example.xml"/>--<!--ADD packages here--><constant name= "Struts.devmode" V Alue= "true"/>< PackageName= "Default" namespace= "/"extends= "Struts-default" ><action name= "Hourse_add"class= "Com.pb.web.action.HourseAction" method= "Add" ><result>addsuccess.jsp</result></action><action name= "Hourse_update"class= "Com.pb.web.action.HourseAction" method= "Update" ><result>updatesuccess.jsp</result></action><action name= "Hourse_del"class= "Com.pb.web.action.HourseAction" method= "Delete" ><result>deletesuccess.jsp</result></action></ Package></struts>

Default Action Configuration

<!--Default Action -<Default-action-refname= "Index" /><Actionname= "Index"><result>index.jsp</result></Action>

Second, using dynamic method invocation

 Packagecom.pb.web.action; Public classuseraction { PublicString Add () {System.out.println ("Perform the Add action! "); return"Success"; }     PublicString Update () {SYSTEM.OUT.PRINTLN ("Perform the update operation!" "); return"Success"; }     PublicString Delete () {System.out.println ("Perform the delete operation! "); return"Success"; }}

Struts.xml

<Packageextendsclass= "Com.pb.web.action.UserAction" ><result>  usersuccess.jsp</result></action>

Page

<!--invoke the specified method using an exclamation point -<formAction= "User!add"><inputtype= "Submit"value= "Add"/></form><formAction= "User!update"><inputtype= "Submit"value= "Update"/></form><formAction= "User!delete"><inputtype= "Submit"value= "Delete"/></form>

Another way of writing

<!--invoke the specified method using an exclamation point -<formAction= "User!add.action"><inputtype= "Submit"value= "Add"/></form><formAction= "User!update.action"><inputtype= "Submit"value= "Update"/></form><formAction= "User!delete.action"><inputtype= "Submit"value= "Delete"/></form>

Third, use wildcard characters to simplify configuration

Action

 Packagecom.pb.web.action; Public classhourseaction { PublicString Add () {System.out.println ("Perform the Add action! "); return"Success"; }     PublicString Update () {SYSTEM.OUT.PRINTLN ("Perform the update operation!" "); return"Success"; }     PublicString Delete () {System.out.println ("Perform the delete operation! "); return"Success"; }}

Struts.xml

<constantname= "Struts.devmode"value= "true" />< Packagename= "Default"namespace="/"extends= "Struts-default"><Actionname= "Hourse_*"class= "Com.pb.web.action.HourseAction"Method= "{1}"><result>{1}success.jsp</result></Action></ Package>

Page

<%@ Page Language="Java"ContentType="text/html; Charset=utf-8"pageencoding="UTF-8"%><!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd "><HTML><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"><title>Insert Title here</title></Head><Body><formAction= "Hourse_add"><inputtype= "Submit"value= "Add"/></form><formAction= "Hourse_update"><inputtype= "Submit"value= "Update"/></form><formAction= "Hourse_delete"><inputtype= "Submit"value= "Delete"/></form></Body></HTML>

STRUTS2 (iv) Action two configuration

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.