1.感叹号
前台页面
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>Insert title here</title>
</head>
<body>
<a href="user!login.action">登录</a><br>
<a href="user!register.action">注册</a>
</body>
</html>
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.enable.DynamicMethodInvocation" value="true"></constant>
<package name="jiangwenwen" namespace="/" extends="struts-default">
<action name="user" class="cn.jiangwenwen.action.UserAction">
<result name="test">/test.jsp</result>
<allowed-methods>login,register</allowed-methods>
</action>
</package>
</struts>
Action方法
package cn.jiangwenwen.action;
import com.opensymphony.xwork2.ActionSupport;
public class UserAction extends ActionSupport{
public String login() {
System.out.println("这是登陆!");
return "test";
}
public String register() {
System.out.println("这是注册!");
return "test";
}
}
2.通配符
jsp页面
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>Insert title here</title>
</head>
<body>
<a href="user_login.action">登录</a><br>
<a href="user_register.action">注册</a>
</body>
</html>
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.enable.DynamicMethodInvocation" value="true"></constant>
<package name="jiangwenwen" namespace="/" extends="struts-default">
<!--使用通配符优化上面的步骤操作,{1}代表*第1次出现的位置-->
<action name="user_*" class="cn.jiangwenwen.action.UserAction" method="{1}">
<result name="test">/test.jsp</result>
<allowed-methods>login,register</allowed-methods>
</action>
</package>
</struts>