struts多个action使用一个配置

1、index页面

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
	DMI User:
	<a href="addUser.action">add</a>
	<a href="delUser.action">del</a>
	<a href="notifyUser.action">notify</a>
	<a href="queryUser.action">query</a>
</body>
</html>

2、struts.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
        "http://struts.apache.org/dtds/struts-2.5.dtd">


<struts>
	<constant name="struts.devMode" value="true"/>
    <package name="default" namespace="/" extends="struts-default">
    	<action name="*User" class="action.HelloWorldAction">
    		<result>
    			{1}User.jsp
    		</result>
    	</action>
    </package>
</struts>

3、HelloWorldAction.java

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
        "http://struts.apache.org/dtds/struts-2.5.dtd">


<struts>
	<constant name="struts.devMode" value="true"/>
    <package name="default" namespace="/" extends="struts-default">
    	<action name="*User" class="action.HelloWorldAction">
    		<result>
    			{1}User.jsp
    		</result>
    	</action>
    </package>
</struts>

4、xxxUser.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
	<h1>add/del</h1>
</body>
</html>


猜你喜欢

转载自blog.csdn.net/qq_28562411/article/details/78629994