溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

springMVC盜鏈接是什么意思

發(fā)布時(shí)間:2021-07-19 09:11:02 來(lái)源:億速云 閱讀:134 作者:chen 欄目:開發(fā)技術(shù)

本篇內(nèi)容介紹了“springMVC盜鏈接是什么意思”的有關(guān)知識(shí),在實(shí)際案例的操作過(guò)程中,不少人都會(huì)遇到這樣的困境,接下來(lái)就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!

目錄
  • springMVC配置文件

    • 登陸驗(yàn)證

    • 登錄的攔截器LoginInterceptor:

    • jsp頁(yè)面: login.jsp

    • main.jsp

    • 驗(yàn)證賬號(hào)密碼

    • 進(jìn)行攔截 登錄才能訪問(wèn)

    • 點(diǎn)擊退出清除session


springMVC配置文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context.xsd
       http://www.springframework.org/schema/mvc
       http://www.springframework.org/schema/mvc/spring-mvc.xsd">
    <!--自動(dòng)掃描包-->
    <!-- 開啟ioc   注解事務(wù)支持-->
    <context:component-scan base-package="cn"></context:component-scan>
    <!--開啟spiring mvc注解支持-->
    <mvc:annotation-driven></mvc:annotation-driven>
    <!--配置spring 中的視圖解析器-->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" id="resolver">
        <property name="prefix" value="/"></property>
        <property name="suffix" value=".jsp"></property>
    </bean>

    <mvc:interceptors>

        <mvc:interceptor>
            <mvc:mapping path="/**"/>
            <bean id="loginInterceptor" class="cn.hp.interceptor.LoginInterceptor"></bean>
        </mvc:interceptor>
    </mvc:interceptors>

</beans>

web.xml文件在我上一篇文章中攔截器https://blog.csdn.net/best_p1/article/details/118637785

登陸驗(yàn)證

package cn.hp.action;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpSession;
@Controller
public class UserAction {
    @RequestMapping("/test1.do")
    public  String test01(){
        System.out.println("正在執(zhí)行test1這個(gè)業(yè)務(wù)邏輯");
        return "index";
    }
    @RequestMapping("/test2.do")
    public  String test02(){
        System.out.println("正在執(zhí)行test2這個(gè)業(yè)務(wù)邏輯");
        return "index";
    }
    @RequestMapping("/login.do")
    public  String login(String userName, String pwd, Model model,HttpSession session){
      if (userName.equals("zs")&&pwd.equals("123")){
          session.setAttribute("user",userName);
          return "redirect:/main.do";
      }else {
          model.addAttribute("msg","用戶名和密碼錯(cuò)誤");
          return "login";
      }
    }
    @RequestMapping("/main.do")
    public String main(){
        return "main";
    }
    @RequestMapping("/loginOut.do")
    public String loginOut(HttpSession session){
        session.invalidate();
        return "login";
    }
}

登錄的攔截器LoginInterceptor:

package cn.hp.interceptor;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
     String path= request.getRequestURI();
     if(path.indexOf("login.do")>0){
         return true;
     }
    Object obj= request.getSession().getAttribute("user");
     if (obj!=null){
         return  true;
     }else {
          request.setAttribute("msg","別想歪心思!請(qǐng)登錄!");
          request.getRequestDispatcher("login.jsp").forward(request,response);
         return false;
     }

    }
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
    }
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
    }
}

jsp頁(yè)面: login.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<form action="login.do" method="post">
    賬號(hào):<input type="text" name="userName"><br/>
    密碼:<input type="password" name="pwd"><br/>
    <input type="submit" value="登錄">
</form>
${msg}
</body>
</html>

main.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
${user}
<a href="loginOut.do">退出</a>
</body>
</html>

springMVC盜鏈接是什么意思

驗(yàn)證賬號(hào)密碼

springMVC盜鏈接是什么意思

進(jìn)行攔截 登錄才能訪問(wèn)

springMVC盜鏈接是什么意思

登錄成功 可以訪問(wèn)test1.do test2.do

點(diǎn)擊退出清除session

springMVC盜鏈接是什么意思

“springMVC盜鏈接是什么意思”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí)可以關(guān)注億速云網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI