首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

两个jsp页面参数传递

2013-07-16 
求助:两个jsp页面参数传递在login.jsp页面接收三个参数,然后传递给image.jsp下面是产生验证码的代码,现在

求助:两个jsp页面参数传递
在login.jsp页面接收三个参数,然后传递给image.jsp
下面是产生验证码的代码,现在需要把image.jsp中的g.setColor(getRandColor(200,250))中随机产生的背景色替换成g.setColor(int a,int b,int c)格式的三个参数,这里面的三个参数就是login.jsp中接收的三个参数。
login.jsp

<%@ page contentType="text/html;charset=gbk" %> 
<%@ page language="java" import="java.sql.*" errorPage="" %> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"> 
<title>用户登录</title> 
<script language="javascript"> 
function loadimage(){ 
document.getElementById("randImage").src = "image.jsp?"+Math.random(); 

</script> 
</head> 
<body> 
<table width="256" border="0" cellpadding="0" cellspacing="0"> 
<!--DWLayoutTable--> 
<form action="validate.jsp" method="post" name="loginForm"> 
<tr> 

<td><input style="width: 100px"  type="text" maxlength="3" id="lab_l" name="lab_l" onafterpaste="this.value=this.value.replace(/\D/g,'')" onkeyup="this.value=this.value.replace(/\D/g,'')">
<input style="width: 100px" type="text" maxlength="5" id="lab_a" name="lab_a" onafterpaste="this.value=this.value.replace(/\D/g,'')" onkeyup="this.value=this.value.replace(/\D/g,'')">
<input style="width: 100px" type="text" maxlength="5" id="lab_b" name="lab_b" >
</td>
<td width="138" valign="middle" align="center"><img alt="两个jsp页面参数传递" name="randImage" id="randImage" src="image.jsp" width="60" height="20" border="1" align="absmiddle"></td> 
</tr> 
<tr> 
<td height="36" colspan="2" align="center" valign="middle"><a href="javascript:loadimage();"><font class=pt95>看不清点我</font></a></td> 
</tr> 
<tr> 
<td height="36" colspan="2" align="center" valign="middle"><input type="submit" name="login" value="提交"></td> 
</tr> 

</form> 
</table> 
</body> 
</html>

image.jsp:
<%@ page contentType="image/jpeg" import="java.awt.*, 
java.awt.image.*,java.util.*,javax.imageio.*" %> 
<%!
Color getRandColor(int fc,int bc)

Random random = new Random(); 
if(fc>255) fc=255; 


if(bc>255) bc=255; 
int r=fc+random.nextInt(bc-fc); 
int g=fc+random.nextInt(bc-fc); 
int b=fc+random.nextInt(bc-fc); 
return new Color(r,g,b); 

%> 
<% 
out.clear();
response.setHeader("Pragma","No-cache"); 
response.setHeader("Cache-Control","no-cache"); 
response.setDateHeader("Expires", 0); 
int width=60, height=20; 
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); 
Graphics g = image.getGraphics(); 
Random random = new Random(); 


g.setColor(getRandColor(200,250)); 
g.fillRect(0, 0, width, height); 
g.setFont(new Font("Times New Roman",Font.PLAIN,18)); 
g.setColor(getRandColor(160,200)); 
for (int i=0;i<155;i++) 

int x = random.nextInt(width); 
int y = random.nextInt(height); 
int xl = random.nextInt(12); 
int yl = random.nextInt(12); 
g.drawLine(x,y,x+xl,y+yl); 

String sRand=""; 
for (int i=0;i<4;i++){ 
String rand=String.valueOf(random.nextInt(10)); 
sRand+=rand; 
g.setColor(new Color(20+random.nextInt(110),20+random.nextInt(110),20+random.nextInt(110))); 
g.drawString(rand,13*i+6,16); 

//将认证码存入SESSION 
session.setAttribute("rand",sRand); 
g.dispose(); 
ImageIO.write(image, "JPEG", response.getOutputStream()); 
%>


现在不能通过提交表单的方式传递参数,需要达到的效果是在login页面接收三个参数,然后点击“看不清点我”,产生的验证码图片背景色是用这三个参数设置的,而不是随机的。求大神解答,这样怎么传递这三个参数啊?万分感谢啊
[解决办法]
不知道有什么困难,图片的地址=  “image.jsp?a=1&b=2&c=3",将login获取的参数a,b,c用js设置下img图片的src,get方式传递进去 
[解决办法]
1#说的是设置img的src属性,附带上参数

function loadimage(){ 
document.getElementById("randImage").src = "image.jsp?"+Math.random()
   +'&l='+document.getElementById("lab_l").value 
   +'&a='+document.getElementById("lab_a").value 


   +'&b='+document.getElementById("lab_b").value 
}

 

热点排行