而不是"A12345AD",,,,,,,,,,"xiaoMing"?
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
把你的代码贴出来瞧瞧######你好红薯大哥,代码我贴出来了######
package com.hxy.service;
import java.io.IOException;
import javax.mail.Session; import javax.servlet.ServletException; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession;
import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.dao.EmptyResultDataAccessException;
import com.hxy.dao.User_CookieDao; import com.hxy.entity.Cookie_UserDemoEntity;
/** * * @author HuangXinyu * * @version 1.0 2012-11-20 下午03:54:24 */ public class LoginService extends HttpServlet {
ApplicationContext act = new ClassPathXmlApplicationContext("bean.xml");
User_CookieDao user_CookieDao = (User_CookieDao) act
.getBean("user_CookieDao");
private static final long serialVersionUID = 8956174527054306717L;
@Override
protected void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
request.setCharacterEncoding("utf-8");
//HttpSession session = request.getSession();
String username = request.getParameter("username");
String pwd = request.getParameter("pwd");
String autologin = request.getParameter("autologin");
if (username != null && !username.equals("") && pwd != null && !pwd.equals("")) {
Cookie_UserDemoEntity userDemoEntity = user_CookieDao.findUser(
username, pwd);
if (userDemoEntity != null) {
if(autologin!=null && !autologin.equals("")){
Cookie ckUsername = new Cookie("A12345AD", username);
ckUsername.setMaxAge(60 * 60 * 24 * 14); //设置Cookie有效期为14天
// String ss = session.getId(); // 取得当前的session id // System.out.println(ss); Cookie[] coolies = request.getCookies(); for(Cookie cookie : coolies){ cookie.getName(); cookie.getValue(); System.out.println(cookie.getName()+",,,,,,,,,,"+cookie.getValue()); } } response.sendRedirect("index.jsp"); // } else if (cs != null) { // // for (int i = 0; i < cs.length; i++) { // Cookie c = cs[i]; // // String cname = c.getName();// 获取的是cookie的名字 // String cvalue = c.getValue();// 获取的是cookie的value值 // // System.out.println(cname + "\t" + cvalue); // }
} else {
request.setAttribute("loginErro", "用户名密码错误!");
request.setAttribute("login", "login/");
request.getRequestDispatcher("/login/login.jsp").forward(request,
response);
return;
}
}else{
request.setAttribute("loginErro", "用户名密码错误!");
request.getRequestDispatcher("/login/login.jsp").forward(request,
response);
return;
}
}
}
######你的代码得到的就应该是显示出来的结果啊,没错哦######回复 @红薯 : 红薯大哥,我加了个response.addCookie(co);就好了居然,好奇怪######回复 @红薯 : 嗯,好的,谢谢了######回复 @xinyu_huang : 那要看 xiaoming 这个值存在哪里,有没有在 cookie 里,你要先确定这个问题######回复 @红薯 : 哦,我怎么样才可以显示xiaoming这个值?######回复 @xinyu_huang : 你这段代码是取所有 cookie 并显示,是没错的