解决方案 »
- Java如何开发SAAS?
- Servlet路径访问问题
- webwork中的ActionContext.getContext().getSession()取到的session为什么是null
- 求助 一个OnSubmit,要怎样合并javascript事件
- 急!如何在页面里显示浏览器端word文件!高手请赐教!
- 用JSTL输出的问题
- 求Unicode转GB312的问题
- 问一个问题我的菜单怎么一闪就不见了
- http://202.96.140.55:34544/BODY&USER=XiHa&PASS=wlchdfyd3Cauc&VERBOSE=0&HISTORY=4&NOPIC=1&,这个端口怎么与IE通讯
- [Microsoft][ODBC Microsoft Access Driver]COUNT 字段不正确???
- jsp中写的页面,怎么在IE中式居中的,在google中不居中
- swfupload不能走后台的action
Map<String,Object> result = new HashMap<String,Object>();
//request.setCharacterEncoding("UTF-8");
String loginname = getRequest().getParameter("loginname");
String loginpwd = getRequest().getParameter("password");
//查看验证码
String scode = (String) session.getAttribute("scode");
System.out.println(scode);
System.out.println(loginname);
System.out.println(loginpwd);
我这个是有的,这个是输入的吧 怎么去获取它生成的那个验证码呢
<tr><td colspan="2" style="height: 36px;"><span id="alert_msg" style="color: red"></span></td></tr>
<tr><td style="text-align: right;width: 40%">用户名</td><td style="text-align: left;width: 60%"><input id="username" type="text" size="22" style="border: 1px solid #09c;"/></td></tr>
<tr><td style="text-align: right;width: 40%">密码</td><td style="text-align: left;width: 60%"><input id="password" type="password" size="22" style="border: 1px solid #09c;" /></td></tr>
<tr><td style="text-align: right;width: 40%">验证码</td><td style="text-align: left;width: 60%"> <input id="checkCode" type="text" size="10" style="border: 1px solid #09c;" /> <img style="width: 60px;height: 24px;vertical-align: middle;border: 1px solid #09c;padding: 0px;" src="http://www.tools138.com/checkCode.htm" onclick="this.src='http://www.tools138.com/checkCode.htm?' + new Date().getTime();" alt="点击更换"/> </td></tr>
<tr><td colspan="2"><input style="margin-left: 200px;" type="button" value="登录" onclick="goSubmit();"/></td></tr>
</table>参考下这个html ,checkcode.htm 这个是Action请求 ,验证的时候跟存在session里面的值进行对比
request.getParameter("scode"); 这个才是获取页面输入的验证码参数一个是Session一个是request
谢谢你,我给你看下完整的登陆验证方法吧,不是我写的不太懂这些,你能帮忙看下怎么改吗public JsonView login(UserVO user) throws Exception{
Map<String,Object> result = new HashMap<String,Object>();
//request.setCharacterEncoding("UTF-8");
String loginname = getRequest().getParameter("loginname");
String loginpwd = getRequest().getParameter("password");
//查看验证码
String scode = (String) session.getAttribute("scode");
System.out.println(scode);
System.out.println(loginname);
System.out.println(loginpwd);
Map param=new HashMap();
param.put("loginname", loginname);
QueryParam qp=QueryParam.getInstance("from UserVO where loginname=:loginname",param);
UserVO vo=(UserVO)this.getBasBS().queryOne(qp);
if(!user.getCode().toUpperCase().equals(scode.toUpperCase())){
//验证码错误
result.put("code_error","验证码错误");
result.put("failure",true);
}
if(vo==null){
result.put("msg", "用户名称不存在!");
result.put("failure", true);
}else{
if (vo.getState()==1){
result.put("msg", "用户已禁用!");
result.put("failure", true);
}
if(MD5Util.md5(loginpwd).equals(vo.getPassword())){
SessionInfo sessionInfo = new SessionInfo();
sessionInfo.setId(vo.getId());
sessionInfo.setName(vo.getName());
sessionInfo.setLoginname(vo.getLoginname());
sessionInfo.setOrgID(Long.parseLong(vo.getOrgid().toString()));
sessionInfo.setUsertype(vo.getUsertype());
//sessionInfo.setMenus(resourceBS.treeByIBatis(vo.getId(),null));
sessionInfo.setResourceList(resourceBS.resourceListByIBatis(vo.getId()));
session.setAttribute(GlobalConstant.SESSION_INFO, sessionInfo);
result.put("success", true);
}else{
result.put("failure", true);
result.put("msg", "密码错误!");
}
}
/*
for(int i=0;i<list.size();i++){
UserVO vo = (UserVO)list.get(i);
System.out.println(vo.getOprid());
System.out.println(vo.getOprname());
}
*/
/*
Iterator it = list.iterator();
while(it.hasNext()){
UserVO vo = (UserVO)it.next();
System.out.println(vo.getOprid());
System.out.println(vo.getOprname());
}*/
JsonView v = new JsonView(result);
v.setContentType("text/html;charset=utf-8");
return v; //new JsonView(result);
}
你生成图片的时候把验证码存入session
然后把这个存入session的跟用户填写的对比不就行了吗!
session.setAttribute("scode",“密码”);
我在jsp里怎么去显示图片呀?不用xml配置和注解
function reloadcode()
{
var verify=document.getElementById('code');
verify.setAttribute('src','getCode.jsp?it='+Math.random());
window.location.href="${ctx}/sys/home/login";
}
<tr>
<td class="login_info" colspan="2">验证码:</td>
<td class="width70" ><input name="code" type="text" class="width70" /></td>
<td width="92" style="text-align:center"><img alt="看不清楚,换一张" src="getCode.jsp" onclick="reloadcode();" id="code" style="position:relative;top:1px;left:0px;"></td>
</tr>
额,这貌似只是个输入框吧,我的完整路径是src="${ctx}/sys/GetCode/execute",其他页面调用方法都是可以的,路径应该没问题
额,这貌似只是个输入框吧,我的完整路径是src="${ctx}/sys/GetCode/execute",其他页面调用方法都是可以的,路径应该没问题
不好意思,刚才弄错了;应该是这样写,把验证码显示出来!
<img alt="看不清楚,换一张" src="${ctx}/sys/GetCode/execute" onclick="reloadcode();" id="code" style="position:relative;top:1px;left:0px;">
额,这貌似只是个输入框吧,我的完整路径是src="${ctx}/sys/GetCode/execute",其他页面调用方法都是可以的,路径应该没问题
不好意思,刚才弄错了;应该是这样写,把验证码显示出来!
<img alt="看不清楚,换一张" src="${ctx}/sys/GetCode/execute" onclick="reloadcode();" id="code" style="position:relative;top:1px;left:0px;">试过了。显示不出来,是我生成验证码的方式有问题吗