Struts2通配符的使用

  • 配置好struts2环境后
LoginAction
package com.login.action;
 
public class LoginAction {
   public String checkLogin() {
      System.out.println("checkLogin");
      return "login";
   }
}
LogoutAction
package com.login.action;
 
public class LogoutAction {
   public String checkLogout() {
      System.out.println("checkLogout");
      return "logout";
   }
}
struts-itcast.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
   "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
   "http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
    <package name="struts2_login" namespace="/" extends="struts-default">
        <action name="*_*" class="com.login.action.{1}Action" method="{2}">
            <result name="login">/loginSuc.jsp</result>
            <result name="logout">/logoutSuc.jsp</result>
            <result name="error">/Error.jsp</result>
        </action>
    </package>
</struts>
struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
   "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
   "http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
   <include file="struts-default.xml" />
   <include file="struts-itcast.xml" />
</struts>

 

Error.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<title>Error</title>
</head>
<body>
<h1>Error</h1>
</body>
</html>
F  login.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
   <head>
   </head>
   <body>
      <a href="Login_checkLogin.action">login</a>
   </body>
</html>
loginSuc.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head><title>login success</title></head>
  <body>
    <h1>Login Success! </h1>
  </body>
</html>
logout.jsp 
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
  <body>
     <a href="Logout_checkLogout.action">logout</a>
  </body>
</html>
logSuc.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head><title>logout success</title></head>
  <body>
    <h1>Logout  Success! </h1>
  </body>
</html>
 

 
posted @ 2014-03-30 21:02  剑风云  阅读(298)  评论(0)    收藏  举报