关于JSP网页的登录界面 我的验证码只有图 没有验证 大神求指导。。。

Joker49 2016-03-29 04:10:26
下面是我的注册页面的代码 JSP 但是输入验证码的正确与否并没有影响到我的网页的登录 验证图片出来了 = = 大神求指导
谢谢~
<%@ page language="java" import="java.util.*,Mod.*,Dal.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'top.jsp' starting page</title>


<link href="css/master.css" rel="stylesheet" type="text/css" />
<link href="css/main.css" rel="stylesheet" type="text/css" />

<base href="<%=basePath%>">

</head>

<%
String incode = (String)request.getParameter("code");
String rightcode = (String)session.getAttribute("rCode");

if(incode != null && rightcode != null){
if(incode.equals(rightcode)){
out.println("验证码输入正确!");
}else{
out.println("验证码输入不正确,请重新输入!");
}
}
%>

<body>
<div class="lefttop"><b>会员中心</b></div>
<%if(session.getAttribute("client")==null){ %>
<form method="post" name="myform" action="Ref/reg.jsp?param=login" onsubmit="return sub()">
<table cellpadding="0" cellspacing="0" id="logintable">
<tr>
<td class="login_left">账号:</td>
<td class="login_right"><input id="Text1" name="login" type="text" /></td>
</tr>
<tr>
<td class="login_left">密码:</td>
<td class="login_right"><input id="Text2" name="pass" type="password" /></td>
</tr>

<tr>
<td class="login_left">验证码: </td>
<td class="login_right"> <img src="number.jsp"/> <input type="text" name="code"/> </td>
</tr>

<tr>
<td class="login_center" colspan="2"><a href="reg.jsp">免费注册?</a></td>
</tr>
<tr>
<td class="login_center" colspan="2">
<input id="Button1" type="submit" value="登陆" />
</td>
</tr>
</table>
</form>
<%}else{
Client left_c=(Client)session.getAttribute("client");
left_c=new ClientServer().GetByID(left_c.getId());
%>
<table cellpadding="0" cellspacing="0" id="logintable">
<tr>
<td class="login_left">登陆名:</td>
<td class="login_right"><%=left_c.getLogin() %><a href="Ref/reg.jsp?param=exit" style="color:#6AA5C7">【退出】</a></td>
</tr>
<tr>
<td class="login_left">姓名:</td>
<td class="login_right"><%=left_c.getName() %></td>
</tr>
<tr>
<td class="login_left">余额:</td>
<td class="login_right"><%=left_c.getMoney() %>元</td>
</tr>
<tr>
<td class="login_center" colspan="2"><a href="myding.jsp">我的申请</a><a href="chong.jsp" style="color:red">在线充值</a></td>
</tr>
<tr>
<td class="login_center" colspan="2"><a href="addcar.jsp">发布车辆</a><a href="mycar.jsp">我的车辆</a></td>
</tr>
<tr>
<td class="login_center" colspan="2"><a href="edit.jsp">修改资料</a><a href="pwd.jsp">修改密码</a></td>
</tr>
</table>
<%} %>


<div class="lefttop"><b>车型种类</b></div>
<div class="leftul">
<ul>
<%
List<CarType> left_type=new CarTypeServer().GetAll();
request.setAttribute("left_type", left_type);
%>
<c:forEach items="${ left_type }" var="t">
<li><a href="car.jsp?type=${t.id }">${t.type }</a></li>
</c:forEach>
</ul>

</div>
</body>
</html>
...全文
145 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
Joker49 2016-03-29
  • 打赏
  • 举报
回复
引用 2 楼 qq_25170731 的回复:
验证码图片应该有个对应的校验码,用户点击登录按钮的时候获得用户输入的验证码,然后把两者做比较,如果一致就提交表单, 你先把type="submit"去掉,写个js函数做校验就行了
我发现上面form action 是调用这里的判断 我把那个判别放到了这里面的 else if里面 但验证码还是没有限制。。你看看这个。。 <%@ page language="java" import="java.util.*,Mod.*,Dal.*" pageEncoding="utf-8"%> <%@ page import="java.text.*"%> <% request.setCharacterEncoding("UTF-8"); String param=request.getParameter("param"); String incode = (String)request.getParameter("code"); String rightcode = (String)session.getAttribute("rCode"); if(param.equals("reg")) { String name=request.getParameter("name"); String sex=request.getParameter("sex"); String age=request.getParameter("age"); String tel=request.getParameter("tel"); String address=request.getParameter("address"); String mail=request.getParameter("mail"); String xueli=request.getParameter("xueli"); String login=request.getParameter("login"); String pass=request.getParameter("pwd1"); //out.print(String.format("姓名:%s,性别:%s,年龄:%s,电话:%s,地址:%s,邮箱:%s,专业:%s,学历:%s,登陆名:%s,密码:%s",name,sex,age,tel,address,mail,zhuanye,xueli,login,pass)); //return; if(new ClientServer().Login(login)!=null) { out.print("<script>alert('该用户名已存在');location.replace('../reg.jsp');</script>"); return; } Client vip=new Client(); vip.setName(name); vip.setSex(sex); vip.setAge(Integer.parseInt(age)); vip.setTel(tel); vip.setAddress(address); vip.setMail(mail); vip.setXueLi(xueli); vip.setLogin(login); vip.setPass(pass); int count=new ClientServer().Add(vip); if(count==0) out.print("<script>alert('操作失败');location.replace('../reg.jsp');</script>"); else out.print("<script>alert('注册成功');location.replace('../index.jsp');</script>"); } else if(param.equals("login")) { String login=request.getParameter("login"); String pass=request.getParameter("pass"); Client v=new ClientServer().Login(login); if(v==null) { out.print("<script>alert('该用户名不存在');location.replace('../index.jsp');</script>"); return; } if(!v.getPass().equals(pass)) { out.print("<script>alert('密码错误');location.replace('../index.jsp');</script>"); return; } session.setAttribute("client",v); out.print("<script>location.replace('../index.jsp');</script>"); return; } else if(incode != null && rightcode != null) { if(incode.equals(rightcode)){ out.println("验证码输入正确!"); }else{ out.println("验证码输入不正确,请重新输入!"); } } else if(param.equals("edit")) { Client v=(Client)session.getAttribute("client"); String name=request.getParameter("name"); String sex=request.getParameter("sex"); String age=request.getParameter("age"); String tel=request.getParameter("tel"); String address=request.getParameter("address"); String mail=request.getParameter("mail"); String xueli=request.getParameter("xueli"); //out.print(String.format("姓名:%s,登陆名:%s,密码:%s,性别:%s,年龄:%s,爱好:%s,说说:%s,身高:%s,已婚状态:%s,学历:%s",name,login,pass,sex,age,hobby,shuoshuo,height,hun,xueli)); //return; v.setName(name); v.setSex(sex); v.setAge(Integer.parseInt(age)); v.setTel(tel); v.setAddress(address); v.setMail(mail); v.setXueLi(xueli); v.setId(v.getId()); int count=new ClientServer().Edit(v); if(count==0) out.print("<script>alert('修改失败');location.replace('../edit.jsp');</script>"); else { session.removeAttribute("client"); session.setAttribute("client",v); out.print("<script>alert('修改成功');location.replace('../edit.jsp');</script>"); } } else if(param.equals("pwd")) { Client v=(Client)session.getAttribute("client"); String pass=request.getParameter("pwd1"); int count=new ClientServer().EditPass(v.getId(),pass); if(count==0) out.print("<script>alert('修改失败');location.replace('../editpass.jsp');</script>"); else out.print("<script>alert('修改成功');location.replace('../editpass.jsp');</script>"); } else if(param.equals("exit")) { if(session.getAttribute("client")!=null) session.removeAttribute("client"); out.print("<script>location.replace('../index.jsp');</script>"); } %>
Joker49 2016-03-29
  • 打赏
  • 举报
回复
引用 2 楼 qq_25170731 的回复:
验证码图片应该有个对应的校验码,用户点击登录按钮的时候获得用户输入的验证码,然后把两者做比较,如果一致就提交表单, 你先把type="submit"去掉,写个js函数做校验就行了
我试了 可能是我没写好 不可以啊 = =
Joker49 2016-03-29
  • 打赏
  • 举报
回复
我试试看 我是小白 = = 不是很会 谢谢
qq_25170731 2016-03-29
  • 打赏
  • 举报
回复
验证码图片应该有个对应的校验码,用户点击登录按钮的时候获得用户输入的验证码,然后把两者做比较,如果一致就提交表单, 你先把type="submit"去掉,写个js函数做校验就行了
Joker49 2016-03-29
  • 打赏
  • 举报
回复
现在就是这个样子。。。但是验证码正确与否没有用。。应该怎么改啊 = =

58,454

社区成员

发帖
与我相关
我的任务
社区描述
Java Eclipse
社区管理员
  • Eclipse
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧