Struts 2 < action > element: establish the mapping of action objects
•
Java
Syntax 1:
url
Example
import com.opensymphony.xwork2.ActionSupport;/**
*用户信息管理Action
*@author zs
*/
public class UserAction extends ActionSupport{
private static final long serialVersionUID=1L; //添加用户信息
public String save()throws Exception{
……
return SUCCESS;
} //修改用户信息
public String update()throws Exception{
……
return SUCCESS;
} //删除用户信息
public String delete()throws Exception{
……
return SUCCESS;
} //查询用户信息
public String find()throws Exception{
……
return SUCCESS;
}
}
<!--添加用户--> <action name="userAction" class="com.lyq.action.UserAction" method="save"> <result>success.jsp</result> </action> <!--修改用户--> <action name="userAction" class="com.lyq.action.UserAction" method="update"> <result>success.jsp</result> </action> <!--删除用户--> <action name="userAction" class="com.lyq.action.UserAction" method="delete"> <result>success.jsp</result> </action> <!--查询用户--> <action name="userAction" class="com.lyq.action.UserAction" method="find"> <result>success.jsp</result> </action>
Syntax 2:
<struts>
<!--定义action-->
<action name="XXX*" class=XXXq.action.{1}XXXAction">
</struts>
Example
import com.opensymphony.xwork2.ActionSupport;/**
*图书Action
*@authorZS
*/
public class BookAction extends ActionSupport{
private static final long serialVersionUID=1L; //添加图书信息请求
public String add()throws Exception{//返回SUCCESS
return SUCCESS;
} //更新图书信息请求
public String update()throws Exception{ //返回SUCCESS
return SUCCESS;
} //删除图书信息请求
public String delete()throws Exception{ //返回SUCCESS
return SUCCESS;
}//查询图书信息请求
public String select()throws Exception{ //返回SUCCESS
return SUCCESS;
} //默认请求执行方法
@Override
public String execute()throws Exception{ //返回SUCCESS
return SUCCESS;
}
}
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.1//EN"
"http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<!--声明常量-->
<constant name="struts.devMode" value="true"></constant>
<package name="myPackage" extends="struts-default" namespace="/">
<!--定义action(使用通配符进行配置)-->
<action name="*_*" class="com.lyq.action.BookAction" method="{1}">
<!--结果映射-->
<result name="success">{2}_{1}.jsp</result>
</action>
</package>
</struts>
<body>
<div align="center">
<h1>图书信息管理</h1>
<a href="https://www.jb51.ccadd_book">添加图书</a>
<a href="https://www.jb51.ccupdate_book">修改图书</a>
<a href="https://www.jb51.ccdelete_book">删除图书</a>
<a href="https://www.jb51.ccselect_book">查询图书</a>
</div>
</body>
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码
