<img>标签导致请求发送两次问题

本文探讨了在Internet Explorer 8(IE8)浏览器中,<img>标签导致请求被发送两次的奇怪现象。通过问题描述和深入分析,揭示了与sessionid相关的原因,并提出了可能的解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题描述:

      原本系统好好的登录页面,我加了一个点击弹出二维码的代码,导致登录不上。排查原因:系统有个session验证,就是页面请求的sessionid必须要跟后台获取的sessionid相同才允许把请求发到后台,后来发现我前端页面加了个<img src="" />,导致sessionid不一致,不允许登录。

问题分析:

     在img 对象的src 属性是空字符串("")的时候,浏览器认为这是一个缺省值,值的内容为当前网页的路径。浏览器会用当前路径进行再一次载入,并把其内容作为图像的二进制内 容并试图显示。所以,登录的时候,页面有两次请求,导致了sessionId前后台不一致。
     上面说的现象不同的浏览器结果不一样,在chome里面就是正常的。
代码 Firefox IE8 谷歌
<img
<!DOCTYPE html> <html lang="en" xmlns:th="http://www.thymeleaf.org"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1,shrink-to-fit=no"> <title>用户登录界面</title> <link th:href="@{/css/bootstrap.css}" rel="stylesheet"> <link th:href="@{/css/signin.css}" rel="stylesheet"> </head> <body class="text-center"> <!-- 用户登录form表单 --> <form class="form-signin" th:action="@{/toBook}"> <img class="mb-4" th:src="@{/img/login.jpg}" width="88" height="88"> <h1 class="h3 mb-3 font-weight-normal" th:text="{login.tip}">请登录</h1> <input type="text" class="form-control" name="username" th:placeholder="{login.username}" required="" autofocus=""> <input type="password" class="form-control" name="password" th:placeholder="{login.password}" required=""> <div class="checkbox mb-3"> <label> <input type="checkbox" value="remember-me"> {login.rememberme} </label> </div> <button class="btn btn-lg btn-primary btn-block" th:text="{login.button}">登录</button> <p class="mt-5 mb-3 text-muted">© <span th:text="${currentYear}"></span>-<span th:text="${currentYear}+1"></span></p> </form> </body> </html> <!DOCTYPE html> <html lang="en" xmlns:th="http://www.thymeleaf.org"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1,shrink-to-fit=no"> <title>用户登录界面</title> <link th:href="@{/css/bootstrap.css}" rel="stylesheet"> <link th:href="@{/css/signin.css}" rel="stylesheet"> </head> <body class="text-center"> <!-- 用户登录form表单 --> <form class="form-signin" th:action="@{/toBook}"> <img class="mb-4" th:src="@{/img/login.jpg}" width="88" height="88"> <h1 class="h3 mb-3 font-weight-normal" th:text="{login.tip}">请登录</h1> <input type="text" class="form-control" name="username" th:placeholder="{login.username}" required="" autofocus=""> <input type="password" class="form-control" name="password" th:placeholder="{login.password}" required=""> <div class="checkbox mb-3"> <label> <input type="checkbox" value="remember-me"> {login.rememberme} </label> </div> <button class="btn btn-lg btn-primary btn-block" th:text="{login.button}">登录</button> <p class="mt-5 mb-3 text-muted">© <span th:text="${currentYear}"></span>-<span th:text="${currentYear}+1"></span></p> </form> </body> </html> 1、整合login.html模板 要求:1) 显示当前年,currentYear~currentYear+1 2) 点击登录后,通过@RequestParam("username")获取输入的用户名,并在控制台打印,登陆后跳转到图书页面
03-31
<template> <div class="bodyMask"> </div> <div id="header" class="index_nav"> <div class="content"> <a href="javascript:void(0);" id="logo"><img src="/images/1504859476522.jpg" height="40" /></a> <ul id="nav"> </ul> <div class="clear"></div> </div> <a id="headSHBtn" href="javascript:void(0);"><i class="fa fa-bars"></i></a> </div> <div id="sitecontent"> <div class="npagePage Pageyemian" id="page_none"> <div id="banner" class=""> <div style="background-image:url(./images/1504853176556.jpg);"></div> </div> <div class="content"> <div class="header"> <p class="title">用户登陆</p> </div> <div class="fw postbody" id="postbody"> <el-form ref="loginForm" :model="loginForm" :rules="rules" style="width:100%;" label-width="20%"> <el-form-item label="用户名" prop="uname"> <el-input v-model="loginForm.uname" placeholder="请输入用户名"></el-input> </el-form-item> <el-form-item label="密码" prop="upwds"> <el-input v-model="loginForm.upwds" placeholder="请输入密码"></el-input> </el-form-item> <el-form-item label="验证码" prop="captcha"> <el-input v-model="loginForm.captcha" placeholder="请输入验证码" style="width: 60%;"></el-input> <!-- 验证码图片 --> <img :src="captchaUrl" alt="验证码" @click="refreshCaptcha" style="cursor: pointer; height: 40px;"/> </el-form-item> <el-form-item> <el-button type="primary" @click="login(loginForm)" :loading="loadingbut">{{loadingbuttext}}</el-button> <el-button type="danger" @click="cancel">重置</el-button> <el-button type="success" @click="$router.push('/register')" >注册</el-button> </el-form-item> </el-form> <p style="text-align: center;"><img src="/images/147626231032.jpg" title="undefined" alt="undefined" width="800" vspace="0" border="0" height="" /></p> <hr /> <p><br /></p> <p><br /></p> </div> </div> </div> </div> <div id="online_open"><i class="fa fa-comments-o"></i></div> <div id="online_lx"> </div> </template> <script> export default { name: 'Login', data () { return { loginForm: { uname: '', upwds: '', captcha: '' }, //验证规则 rules: { uname: [{required: true, message: '请输入用户名', trigger: 'blur'}], upwds: [{required: true, message: '请输入密码', trigger: 'blur'}], captcha: [{required: true, message: '请输入验证码', trigger: 'blur'}] }, loadingbut: false, loadingbuttext: '登录', captchaUrl: '/captcha', // 验证码图片的URL dialogVisible: true } }, mounted () { console.log('Captcha URL:', this.captchaUrl); }, methods: { login (loginForm) { this.$refs['loginForm'].validate((valid) => { if (valid) { this.loadingbut = true this.loadingbuttext = '登录中...' this.$axios .post('/logins',{ uname: loginForm.uname, upwds: loginForm.upwds, captcha: loginForm.captcha }) .then(successResponse => { if (successResponse.data === "ok") { //Message Box this.$alert('登录成功', {confirmButtonText: '确定' }) this.$store.commit('changeLogin',this.loginForm.uname) let path = this.$route.query.redirect this.$router.replace({path: path === '/' || path === undefined ? '/mains': path}) }else { this.$alert('用户名或密码错误或验证码错误!', {confirmButtonText: '确定' }) this.loadingbut = false; this.loadingbuttext = '登录'; } }) .catch(failResponse => { this.$alert(failResponse.response.status, {confirmButtonText: '确定' }) }) } else { this.$alert('表单验证失败', {confirmButtonText: '确定' }) return false; } }) }, cancel(){ this.$refs['loginForm'].resetFields() }, refreshCaptcha () { // 刷新验证码 this.captchaUrl = `/captcha?timestamp=${new Date().getTime()}` } } } </script> <style scoped> @import '../../public/css/4101.css'; @import '../../public/css/lib.css'; @import '../../public/css/style.css'; </style> 为什么这么写验证码显现不出来
05-11
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值