<%@ page language="java" contentType="text/html; charset=gb2312"
    pageEncoding="gb2312" import="com.my.bean.AdministerLoginServlet"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Login</title>
</head>
<body>
<form action=" com.my.bean.AdministerLoginServlet"  method=post name=test>
用户名:<input type="text" name=aid><br>
密码:<input  type="text" name=apwd><br><input type="submit"  name="Login" value="登录">
</form>
</body>
</html> 这是登陆界面
另外,我是用Servlet处理的的登陆页面的请求
下面的代码是用来处理登录请求的Servlet代码package com.my.bean;
import java.io.*;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class AdministerLoginServlet  extends HttpServlet{
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, java.io.IOException {
response.setContentType("text/html;charset=gb2312");
    PrintWriter  out=response.getWriter();
    String   strname=request.getParameter("name4");//获得登录名
    System.out.println(strname);
    System.out.println("获得登录名"); 
        String  id=request.getParameter("aid");
     String  pwd=request.getParameter("apwd");
     id=getS(id);
     pwd=getS(pwd);
     Administer a=new Administer();
     a.setAid(id);
     a.setApwd(pwd);
     if(a.Login()){
HttpSession session=request.getSession(true);
    session.setAttribute("aid",id);
    session.setAttribute("apwd",pwd);
    response.sendRedirect("Administer.jsp");
}
else{
//System.out.println("<script language='javaScript'>window.alert('用户名或密码错误,请确认')</script>");
//System.out.println("<script language='javaScript'>window.location=AdministerLogin.jsp</script>");
//System.out.println("<script language='JavaScript'>window.alert('用户名或密码错误,请确认')</script>");
 response.sendRedirect("AdministerLoginError.jsp");
}
         
    }
    
    public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, java.io.IOException {
doPost(request,response);
}
 public String getS(String s){
         try{
               byte b[]=s.getBytes("iso-8859-1");
               s=new String(b);
               return s;
            }
         catch(Exception e){
            return e.toString();
          }
       }

}

解决方案 »

  1.   

    方法一:在jsp页面上写<%=session.getAttribute("aid")%>
    方法二:在jsp页面上写${aid }
      

  2.   

      <%=request.getAttribute("aid")%>

    ${aid}
      

  3.   

    你在登陆的时候要把用户的信息取出来,最好放到session作用域范围中,然后去修改页面时把信息从session中取出来显示。然后修改就可以了。
      

  4.   

    在登录成功的时候,帮当前登录的user对象放到session中(request.getSession().setAttribute("loguser",user));如果你想修改就从session中把当前登录的user取出来,再修改(request.getSession.getAttribute("loguser"))。希望对你有帮助。
      

  5.   

    我现在用Session保存后在JSP页面中能使用了,但是我不知道在另外一个Servlet(处理修改信息请求)中怎么使用,我想用String id= request.getAttribute("aid");但是还是不对
      

  6.   

    最好建个对象来保存有用的信息,  当然也可以直接用那个user对象咯,
    如果登录成功, 把该对象放在入session中,
    页面上就可以直接取咯,重要的一点是,
    这好像不用JSP牛人就可以解决的问题呀
      

  7.   

     呵呵 点击修改按钮 请求url+用户名参数 一起提交不就可以了,,
    如果含有中文 写设置下编码方式就可以了,,放范围对象里 也可以。
    建议用户一登陆 就把它保存在范围对象中,后面跟他有关的操作就简单了。
    还可以判断一些权限问题什么的
      

  8.   

    在JSP页面中直接用EL表达式咯如在session中, ${sessionScope.aid}
    或者直接用${aid}
      

  9.   


    你这里要用 String id= (String)request.getSession().getAttribute("aid")
      

  10.   

    放到session中,然后再jsp中取出来
      

  11.   

    从session中获取信息,是从session获取并不是在 request.getAttribute("aid"); request中获取.
    String id=(String)request.getSession().getAttribute("aid");返回字符串的ID
      

  12.   

    String id=(String)request.getSession().getAttribute("aid");
      

  13.   

    登陆后将用户名信息保存到session
    不管你在哪个servlet中,都能获取到自己session中的用户名