二 调用验证码的方法
package com.sorfteem.informationsystem.until;import java.io.IOException;
import java.io.PrintWriter;import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;public class CheckNumber extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request,response);}public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
HttpSession session=request.getSession();
if (session!=null) {
String myrnd=RndImage.random();
System.out.println(myrnd+"<<<<<<<<<<<<<<<");
session.setAttribute("rnd", myrnd);
response.setContentType("image/jpeg");
RndImage.ImageOut(myrnd,response.getOutputStream(),80,20);
}}}三:登陆页面的JSp
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
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>
<base href="<%=basePath%>"><title>企业信息管理系统 - 登录</title><meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="企业,信息,管理">
<meta http-equiv="description" content="企业信息管理系统 - 登录窗口">
<meta http-equiv="Content-Type" content="text ml; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="css/styles.css">
<script language="javascript">
function validLogin(theform) {
var username = theform.username.value;
var password = theform.password.value;
var code=theform.code.value;
if (username == "") {
alert("用户名不能为空!");
return false;
}
if (password == "") {
alert("密码不能为空!");
return false;
}
if(code == ""){
alert("验证码!");
return false;
}
return true;
}
</script>
</head>
<body bgcolor="#52BDFE">
<table height="100%" width="100%">
<tr>
<td align="center">
<table width="572" height="307" background="images/login.jpg">
<tr>
<td width="60%"></td>
<td>
<form name="form1" action="WelcomeServlet" method="post"
onsubmit="return validLogin(this);">
<table>
<tr>
<td>
用户名:
</td>
<td>
<input type="text" name="username" size="10">
</td>
</tr>
<tr>
<td>
密 码:
</td>
<td>
<input type="password" name="password" size="10">
</td>
</tr>
<tr>
<td>
<img id="rnd" src="/InformationSystem/CheckNumber" border="0"/>
</td>
<td> <input type="hidden" name="rnd" value='<%=request.getAttribute("rnd")+"1234" %>'/>
<input name="code" type="text" size="4" />
</td>
</tr>
<tr>
<td colspan="2">
<a href="register.jsp">注册新用户</a>
<input type="submit" name="submit" value="登录系统">
</td>
</tr></table>
</form>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
< ml>请问怎么把二 调用验证码的方法
里面的rnd 值传递到 login页面里的 <input type="hidden" name="rnd" value='<%=request.getAttribute("rnd")+"1234" %>'/>
package com.sorfteem.informationsystem.until;import java.io.IOException;
import java.io.PrintWriter;import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;public class CheckNumber extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request,response);}public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
HttpSession session=request.getSession();
if (session!=null) {
String myrnd=RndImage.random();
System.out.println(myrnd+"<<<<<<<<<<<<<<<");
session.setAttribute("rnd", myrnd);
response.setContentType("image/jpeg");
RndImage.ImageOut(myrnd,response.getOutputStream(),80,20);
}}}三:登陆页面的JSp
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
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>
<base href="<%=basePath%>"><title>企业信息管理系统 - 登录</title><meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="企业,信息,管理">
<meta http-equiv="description" content="企业信息管理系统 - 登录窗口">
<meta http-equiv="Content-Type" content="text ml; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="css/styles.css">
<script language="javascript">
function validLogin(theform) {
var username = theform.username.value;
var password = theform.password.value;
var code=theform.code.value;
if (username == "") {
alert("用户名不能为空!");
return false;
}
if (password == "") {
alert("密码不能为空!");
return false;
}
if(code == ""){
alert("验证码!");
return false;
}
return true;
}
</script>
</head>
<body bgcolor="#52BDFE">
<table height="100%" width="100%">
<tr>
<td align="center">
<table width="572" height="307" background="images/login.jpg">
<tr>
<td width="60%"></td>
<td>
<form name="form1" action="WelcomeServlet" method="post"
onsubmit="return validLogin(this);">
<table>
<tr>
<td>
用户名:
</td>
<td>
<input type="text" name="username" size="10">
</td>
</tr>
<tr>
<td>
密 码:
</td>
<td>
<input type="password" name="password" size="10">
</td>
</tr>
<tr>
<td>
<img id="rnd" src="/InformationSystem/CheckNumber" border="0"/>
</td>
<td> <input type="hidden" name="rnd" value='<%=request.getAttribute("rnd")+"1234" %>'/>
<input name="code" type="text" size="4" />
</td>
</tr>
<tr>
<td colspan="2">
<a href="register.jsp">注册新用户</a>
<input type="submit" name="submit" value="登录系统">
</td>
</tr></table>
</form>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
< ml>请问怎么把二 调用验证码的方法
里面的rnd 值传递到 login页面里的 <input type="hidden" name="rnd" value='<%=request.getAttribute("rnd")+"1234" %>'/>
解决方案 »
- 打印报表的问题net.sf.jasperreports.engine.JRException:Error loading object from URL
- java内存回收机制问题
- 对文件夹使用listFiles(),当文件夹中文件过多有何影响
- 关于request一个问题的疑惑
- java web打印的问题?
- 求助--谁有struts2+hibernate+mysql做的web小系统。。
- 我不会的一个问题,请教大家拉!!!
- Hibernate事务的rollback在try, catch, finally中的位置问题??
- j2ee和sun(tm)one studio的联系与区别是什么啊?急!!!
- RMI服务器端程序出现ClassNotFound异常
- struts2的核心是什么,实现零配置的插件是什么,struts有哪些版本,struts的拦截器有哪些?
- 身份验证怎么做?
这样,取不到吗?
session.setAttribute("rnd", myrnd);
在页面取也要session范围~~~request取不到~~~
后台都放到session里了
页面里也得用session取啊