登录业务逻辑

登录业务逻辑

修改 web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
         version="4.0">
    <!-- 不加载无用Jar包 -->
    <absolute-ordering/>

    <!--核心过滤器-->
    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <!--Spring的核心监听器-->
    <listener>
        <listener-class>
            org.springframework.web.context.ContextLoaderListener
        </listener-class>
    </listener>

    <!--
     加载Spring的配置文件的路径的
     默认加载的/WEB-INF/applicationContext.xml
     -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:applicationContext.xml</param-value>
    </context-param>

    <!-- 欢迎页,也就是启动项目默认系统访问的页面 -->
    <welcome-file-list>
        <welcome-file>mgr_login.jsp</welcome-file>
    </welcome-file-list>
</web-app>

修改 web/mgr_login.jsp

<form action="${pageContext.request.contextPath}/loginAction_login.action" id="login_form">
    <div class="login">博客后台管理系统</div>
    <div class="username-text">用户名:</div>
    <div class="password-text">密码:</div>
    <div class="username-field">
        <input type="text" name="username" value="BNTang"/>
    </div>
    <div class="password-field">
        <input type="password" name="password" value="1234"/>
    </div>
    <input type="checkbox" name="remember-me" id="remember-me"/>
    <label for="remember-me">记住用户名</label>
    <div class="forgot-usr-pwd"></div>
    <input type="submit" name="submit" value="登录" style="font-size: 16px;margin-top:-1px;"/>
</form>	

在 src/top/it6666/web 中添加 LoginAction

package top.it6666.web;

import com.opensymphony.xwork2.ActionSupport;

/**
 * @author tangyihao
 * @version V1.1.1
 * @program it6666-Blog
 * @date Created in 2020/9/3 8:53
 * @description 登陆Action
 **/
public class LoginAction extends ActionSupport {

    public String login() {
        System.out.println("login来了");
        return null;
    }
}

修改 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>
    <package name="struts" extends="struts-default">
        <action name="loginAction_*" class="top.it6666.web.LoginAction" method="{1}">
            <allowed-methods>login</allowed-methods>
        </action>
    </package>
</struts>
posted @ 2020-09-03 10:19  BNTang  阅读(134)  评论(0编辑  收藏  举报