很多人对struts2中的使用不了解,经过研究,特备案
网页中的书写方式
<body>
网页中的书写方式
<body>
<!-- workA:常用的直接调用execute 方法,默认的方法 -->
<form action="test.action" method="post">
<input type="text" id="name" name="name"/>
execute
<input type="submit"/>
</form>
<!-- workB:直接使用 method来进行 非 execute方法的调用 -->
<form action="testA.action" method="post">
<input type="text" id="name" name="name"/>
调用其他方法OK
<input type="submit"/>
</form>
<!-- workC:和testB用于!连接的例子 -->
<form action="testB!update.action" method="post">
<input type="text" id="name" name="name"/>
调用其他方法update
<input type="submit"/>
</form>
<!-- workD:通配符的使用* 但是通配符会加大系统的负担,所以一般情况下不建议使用 -->
<form action="test_add.action" method="post">
<input type="text" id="name" name="name"/>
通配符
<input type="submit"/>
</form>
</body>
配置文件中的书写方式。
<?xml version="1.0" encoding="UTF-8"?>
配置文件中的书写方式。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
<struts>
<constant name="struts.enable.DynamicMethodInvocation" value="true" />
<!-- 和testB一起用于 ! 进行非 execute 方法的调用 用于开启!的使用-->
<package name="default" extends="struts-default" namespace="/" strict-method-invocation="false">
<!--strict-method-invocation用于 * 通配符的使用,开启统配符号 -->
<!-- workA:常用的直接调用execute 方法,默认的方法 -->
<action name="test" class="com.action.LoginAction">
<result name="scrount">index.jsp</result>
</action>
<!-- workB:直接使用 method来进行 非 execute方法的调用 -->
<action name="testA" class="com.action.LoginAction" method="delete">
<result name="scrount">index.jsp</result>
</action>
<!-- workC:和testB用于!连接的例子 -->
<action name="testB" class="com.action.LoginAction">
<result name="scrount">index.jsp</result>
</action>
<!-- workD:通配符的使用* 但是通配符会加大系统的负担,所以一般情况下不建议使用 -->
<action name="test_*" class="com.action.LoginAction" method="{1}">
<result name="scrount">index.jsp</result>
</action>
</package>
</struts>
LoginAction中的方法的书写方式:
LoginAction中的方法的书写方式:
public String execute() throws Exception {
// TODO Auto-generated method stub
System.out.println("ex");
return "scrount";
}
public String delete() throws Exception{
System.out.println("delete");
return "scrount";
}
public String add() throws Exception{
System.out.println("add");
return "scrount";
}
public String update() throws Exception{
System.out.println("update");
return "scrount";
}