struts访问流程

来源:互联网 发布:淘宝介入的原则 编辑:程序博客网 时间:2024/06/08 14:02

1.web.xml配置

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  <display-name></display-name>    
      <filter>  
            <filter-name>struts2</filter-name>  
            <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>  
    </filter>      
     <filter-mapping>  
            <filter-name>struts2</filter-name>  
            <url-pattern>*.action</url-pattern>  
     </filter-mapping>  
      <welcome-file-list>
    <welcome-file>login.jsp</welcome-file>
  </welcome-file-list>
</web-app>

.会通过上面<welcome-file-list>  <welcome-file>login.jsp</welcome-file></welcome-file-list>先访问登录页面

2.login.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>  

    <html>  
      <head>       
        <title>用户登录界面</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> 
        <form action="login.action" method="post">  
            用户名:<input type="text" name="userName"/><br/>  
            密码:<input type="password" name="password"/><br/>  
            <input type="submit" value="提交"/>  
        </form>  
      </body>  

    </html> 

通过提交表单中的login.action,去找struts.xml中的配置

3.struts.xml

<?xml version="1.0" encoding="UTF-8" ?>  
    <!DOCTYPE struts PUBLIC  
        "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"  
        "http://struts.apache.org/dtds/struts-2.0.dtd">  
    <struts>  
         <package name="test"  extends="struts-default">  
            <action name="login" class="com.suo.Login" method="execute">  
                <result name="success">/WEB-INF/jsp/success.jsp</result>  
                <result name="fail">/WEB-INF/jsp/fail.jsp</result>  
            </action>  
         </package>  
</struts> 
找到匹配的action名称login找到,这个action的类的位置,和执行方法,根据方法执行结果进行跳转



0 0