黑马程序员技术交流社区
标题:
//产生登录界面 //获取特定的cookie
[打印本页]
作者:
tfy
时间:
2012-12-24 21:54
标题:
//产生登录界面 //获取特定的cookie
package com.itheima.cookie.app2;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
//产生登录界面
//获取特定的cookie
public class LoginServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out=response.getWriter();
//获取特定Cookie
String username="";
String checked="";
Cookie []cs=request.getCookies();
for(int i=0;cs!=null&&i<cs.length;i++){
if(Constants.USERINFO.equals(cs[i].getName())){
//找到啦
username=cs[i].getValue();
checked="checked='checked'";
}
}
out.write("<form action='"+request.getContextPath()+"/servlet/ResultServlet' method='post'>");
out.write("用户名:<input type='text' name='username' value='"+username+"'/><br/>");
out.write("密码:<input type='password' name='password' value=''/><br/>");
out.write("<input type='checkbox' name='remember'"+checked+" />记住用户名<br/>");
out.write("<input type='submit' value='登录'/><br/>");
out.write("</form>");
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
}
作者:
济南王昭珽
时间:
2012-12-25 10:41
发现了一个问题,粘贴我的源码,什么时候粘贴你写出的源码啊,希望能看到
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2