最近一个项目要实现记住用户名的功能,小弟不才,找了很多资料都无法实现功能...流程是这样,页面有一name="checkbox",后台获得后创建cookie,cookie.setPath这个方法,没搞懂,因为我找不到这个后台实现的cookie文件,然后前台login的时候查找cookie,将匹配的填入<input type="text" name="username">,不知道理解的对不对...哪位大虾能将实现的具体代码贴一下,谢谢!
解决方案 »
- jetty启动spring报错Read and write parameter types are not the same
- webwork(或struts2)的问题
- 百分求解一个hibernate的问题
- 现有大型办公自动化系统,因为模块太多,登录人员多,考虑将模块分开安装,不知用什么框架或技术好?
- 为什么页面老不刷新,删除了tomcat目录下的\work\Catalina\localhost\_ ,再点击页面才刷新
- 到底什么才是web service啊??:(
- 新手问题:为什么我这样编译出错。
- 关于在CMP中做查询处理
- EJB的配置问题
- 只知道类名字符串(不知路径)如何转换为Class 类型
- SQL语句 怎么分组显示重复
- 新手求教JAVA WEB开发问题!
cookie.setPath("/");//取客户端cookie的方法:
Cookie[] cookies = request.getCookie();//发送cookie的方法
response.sendCookie(cookie对象);
<form method="post" action="loginManager.jsp">
<input type="text" name="userName">
<input type="password" name="uerPwd">
<input type="checkBox" name="autoLogin">
<input type="submit" name="submit">
</form>loginManager.jsp
<%
String uName=request.getParameter("userName");
String uPwd=request.getParameter("userPwd");
String auto=request.getParameter("autoLogin");
if(用户名.equals(uName)&&密码.equals(uPwd)){
session.setAttribute("user",userName);
if(auto!=null){
Cookie cName=new Cookie("name",uName);
Cookie cPwd=new Cookie("pwd",uPwd);
cName.setMaxAge(999999);
cPwd.setMaxAge(999999);
response.add(cName);
response.add(cPwd);
}
response.sendRedirect("success.jsp");
}
%>index.jsp
<%
Cookie[] cookie=request.getCookies();
String name="";
String pwd="";
if(cookie!=null){
for(Cookie c:cookies){
String key=c.getName();
if("name".equals(key)){
name=c.getValue;
}
if("pwd".equals(key)){
value=c.getValue();
}
}
}
if(!name.isEmpty&&!pwd.isEmpty){
response.sendRedirect("loginManager.jsp?userName="+name+"&userPwd="+pwd);
}else{
response.sendRedirect("lgoin.jsp");}
%>
取得cookie的值后,是放在text里,还是传到服务器端就看你自己的了