当前位置: 技术问答>java相关
使用session问题
来源: 互联网 发布时间:2015-08-23
本文导语: 我要从当前浏览器窗口中读书取其他程序写的session("Username") 我在servlet中该如何处理? | 这样试试看。 import javax.servlet.http.*; import javax.servlet.*; import java.io.*; public class check extends HttpServ...
我要从当前浏览器窗口中读书取其他程序写的session("Username")
我在servlet中该如何处理?
我在servlet中该如何处理?
|
这样试试看。
import javax.servlet.http.*;
import javax.servlet.*;
import java.io.*;
public class check extends HttpServlet{
public check(){
super();
}
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
response.setContentType("text/html; charset=GBK");
PrintWriter out = response.getWriter();
//session.setAttribute("Check_User",OK);
HttpSession session=request.getSession();
String ss="";
if(session.getAttribute("Check_User")==null){
ss = "";
}else {
ss=(String)session.getAttribute("Check_User");
}
if (ss == null)
out.print("NULL");
if (ss != null)
{
out.print("
}
else
{
out.print("
}
out.print("");
}
}
import javax.servlet.http.*;
import javax.servlet.*;
import java.io.*;
public class check extends HttpServlet{
public check(){
super();
}
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
response.setContentType("text/html; charset=GBK");
PrintWriter out = response.getWriter();
//session.setAttribute("Check_User",OK);
HttpSession session=request.getSession();
String ss="";
if(session.getAttribute("Check_User")==null){
ss = "";
}else {
ss=(String)session.getAttribute("Check_User");
}
if (ss == null)
out.print("NULL");
if (ss != null)
{
out.print("
身份确认
");}
else
{
out.print("
认证失败
");}
out.print("");
}
}
|
没在头部import java.io.*吧?
|
或许是你immport了两个都含有IOException或者PrintWriter类的包,所以你要具体指定那一个.
|
HttpSession mysession = pageContext.getSession();
String temp;
temp = mysession.getAttibute("Username");
String temp;
temp = mysession.getAttibute("Username");
|
Session session=request.Session;
String temp;
temp = mysession.getAttibute("Username");
String temp;
temp = mysession.getAttibute("Username");
|
没有.
|
你没有import java.io.*;