================================================这个是打开首页的一个jsp页面===================================================
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<!-- 这个方法是明确action调用那个方法 -->
<input type="button" value="添加" οnclick="return window.location='add'"/>
<input type="button" value="删除" οnclick="return window.location='delete'"/>
<!-- 这个是DMI动态调用action的方法 关键在 userManage!add 注解:userManage是action的name的值 !表示调用那个 比如add -->
<input type="button" value="添加_1" οnclick="return window.location='userManage!add'"/>
<input type="button" value="删除_1" οnclick="return window.location='userManage!delete'"/>
</body>
</html>
=============================================这个是Action==================================================================
package org.demo.struts;
import com.opensymphony.xwork2.ActionSupport;
public class UserManage extends ActionSupport {
/** 这个是第一种用method方法明确指定调用的方法
public String add() {
return SUCCESS;
}
public String delete() {
return SUCCESS;
}
*/
//下面这个这用DMI动态执行方法
public String add() {
return "add_success";
}
public String delete() {
return "delete_success";
}
}
================================================这个是struts.xml 中的配置=====================================================
<?xml version="1.0" encoding="UTF-8" ?>
<!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"/>
<package name="UserManage" namespace="/" extends="struts-default">
<!-- 这个配置是明确告诉action调用那个方法
<action name="add" class="org.demo.struts.UserManage" method="add">
<result name="success">add.jsp</result>
</action>
<action name="delete" class="org.demo.struts.UserManage" method="delete">
<result name="success">delete.jsp</result>
</action>
-->
<!-- 这个方法是DMI动态调用那个方法 的配置 只用一个action-->
<action name="userManage" class="org.demo.struts.UserManage">
<result name="add_success">add.jsp</result>
<result name="delete_success">delete.jsp</result>
</action>
</package>
</struts>
========================================这里有两个add.jsp ,和delete.jsp页面执行 是分别执行action中的add(),delete()中的跳转页面==================