正在回答 回答被采纳积分+1
2回答
懒人13
2019-09-11 19:45:11
我在Servlet中取得的两个值是正常的,在jsp页面中的function()中就是这样,下面是JSP页面代码
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt"%>
<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>登录页面</title>
<style type="text/css">
a
{
text-decoration:none;
font-size:12px;
color:#288bc4;
}
a:hover
{
text-decoration:underline;
}
</style>
</head>
<body>
<center>
<h1>用户登录</h1>
<p style="color: red">${msg}</p>
<form action="<%=basePath%>/LoginServlet" method="post" onsubmit="return validateCode()">
<table width="300px" cellspacing="0px" cellpadding="0px" border="1px">
<tr>
<td>用户名</td>
<td colspan="2"><input type="text" id="username" name="username" placeholder="用户名为3-12位字母数字或下划线组合"></td>
</tr>
<tr>
<td>密 码</td>
<td colspan="2"><input type="password" id="password" name="password" placeholder="长度为5-12位字母数字或下划线组合" ></td>
</tr>
<tr style="height:40px">
<td>验证码</td>
<td style="border-right-style:none;">
<input type="text" name="inputCode" id="inputCode" placeholder="请输入验证码" maxlength="4">
</td>
<td style="border-left-style:none;">
<div class="" id="checkCode" >
<form action="submit.action">
<img src="<%=basePath %>/kaptcha.jpg" id="kaptchaImg"/>
</form>
</div>
</td>
</tr>
<tr>
<td colspan="3" style="text-align:center">
<input type="submit" id="login" value="登录">
<input type="reset" value="取消">
</td>
</tr>
</table>
</form>
</center>
<script src="<%=request.getContextPath()%>/js/jquery-3.3.1.js" type="text/javascript"></script>
<script>
$(function () {
$("#kaptchaImg").on("click", function () {
$(this).attr("src", "<%=basePath%>/kaptcha.jpg?d=" + new Date().getTime());
});
$("#login").on("click",function(){
//获取生成的验证码
var kcode= '<%= request.getSession().getAttribute("kcode")%>';
//获取用户输入的验证码
var inputcode = $("#inputCode").val();
alert("生成验证码:"+kcode+" 用户输入验证码:"+inputcode);
<%--if(kcode != inputcode){--%>
<%-- alert("验证码输入有误!");--%>
<%-- window.navigator("<%=basePath%>/index");--%>
<%--}--%>
});
})
</script>
</body>
</html>
从网页搭建入门Java Web2018版
- 参与学习 人
- 提交作业 1088 份
- 解答问题 10204 个
如果你有Java语言基础,又想以后从事Java Web开发,那么本路径是你的不二选择!本路径从网页搭建开始入手,通过大量案例来学习Java Web基础。定能助你完成Java Web小白的蜕变!
了解课程

恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星