| |
|
|
|
你也可以这样玩:
action:
<action name="*_Action" class="com.deng.PersonInfo" method="{1}" >
<result name="add">/example/add.jsp</result>
<result name="update">/example/update.jsp</result>
<result name="delete">/example/delete.jsp</result>
</action>
jsp:
<a href="example/add_Action.action">增加</a><br>
<a href="example/delete_Action.action">删除</a><br>
<a href="example/update_Action.action">修改</a><br>
学东西不要只看视频学,要多动脑筋,看原理。视频只是给你一个大概轮廓,实际中开发中与视频是不
相同的,哥们!
---------------------------------------------------------------------------------------------------------------------------------------------------
现在的主流搞法都是annotation无配置文件,你再看看这样玩:
web.xml中配置FilterDispatcher,代码如下
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
<init-param>
<param-name>actionPackages</param-name>
<param-value>com.deng.action</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
action:
LoginAction.java
package com.deng.action;
import java.util.Map;
import org.apache.struts2.config.NullResult;
import org.apache.struts2.config.ParentPackage;
import org.apache.struts2.config.Result;
import org.apache.struts2.config.Results;
import org.apache.struts2.dispatcher.ServletActionRedirectResult;
import org.apache.struts2.interceptor.SessionAware;
import com.opensymphony.xwork2.ActionSupport;
@Results( {
@Result(name ="add", value = "/add.jsp", type = NullResult.class),
@Result(name ="update", value = "/update.jsp", type = NullResult.class),
@Result(name ="delete", value = "/delete.jsp", type = NullResult.class),
@Result(name ="query", value = "/query.jsp", type = NullResult.class)
})
public class LoginAction extends ActionSupport{
public String update() {
System.out.println("--update--");
return "update";
}
public String delete() {
System.out.println("--delete--");
return "delete";
}
public String add() {
System.out.println("--add--");
return "add";
}
public String query() {
System.out.println("--query--");
return "query";
}
@Override
public String execute() throws Exception {
System.out.println("----默认进入方法!---");
return null;
}
}
相关jsp页面:
index.jsp:
<a href="login!add.action">增加</a><br>
<a href="login!delete.action">删除</a><br>
<a href="login!update.action">修改</a><br>
<a href="login!query.action">查找</a><br>