jsp牛人请进!!!!!用jsp做好登录界面,想在个人主页上添加修改个人信息功能!可是不知道怎么获得用户名!!!!在线求高人指点!

J5175 2011-05-12 08:57:12
<%@ 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();
}
}

}
...全文
1651 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
jiangjian0427 2011-05-12
  • 打赏
  • 举报
回复
放到session里面
zjt321 2011-05-12
  • 打赏
  • 举报
回复
在登录成功的时候,帮当前登录的user对象放到session中(request.getSession().setAttribute("loguser",user));如果你想修改就从session中把当前登录的user取出来,再修改(request.getSession.getAttribute("loguser"))。

希望对你有帮助。
licip 2011-05-12
  • 打赏
  • 举报
回复
你在登陆的时候要把用户的信息取出来,最好放到session作用域范围中,然后去修改页面时把信息从session中取出来显示。然后修改就可以了。
  • 打赏
  • 举报
回复
<%=request.getAttribute("aid")%>

${aid}
jingyuwang1 2011-05-12
  • 打赏
  • 举报
回复
方法一:在jsp页面上写<%=session.getAttribute("aid")%>
方法二:在jsp页面上写${aid }
miprasun 2011-05-12
  • 打赏
  • 举报
回复
Session或Cookie都可以
yyil80 2011-05-12
  • 打赏
  • 举报
回复
sisson操作就可以了
梦魇23号 2011-05-12
  • 打赏
  • 举报
回复
登陆后将用户名信息保存到session
不管你在哪个servlet中,都能获取到自己session中的用户名。。。
javaxuezi 2011-05-12
  • 打赏
  • 举报
回复
String id=(String)request.getSession().getAttribute("aid");
zr167173 2011-05-12
  • 打赏
  • 举报
回复
从session中获取信息,是从session获取并不是在 request.getAttribute("aid"); request中获取.
String id=(String)request.getSession().getAttribute("aid");返回字符串的ID
ekekyn 2011-05-12
  • 打赏
  • 举报
回复
放到session中,然后再jsp中取出来
仲兴轩 2011-05-12
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 j5175 的回复:]
我现在用Session保存后在JSP页面中能使用了,但是我不知道在另外一个Servlet(处理修改信息请求)中怎么使用,我想用String id= request.getAttribute("aid");但是还是不对
[/Quote]

你这里要用

String id= (String)request.getSession().getAttribute("aid")
仲兴轩 2011-05-12
  • 打赏
  • 举报
回复
在JSP页面中直接用EL表达式咯

如在session中, ${sessionScope.aid}
或者直接用${aid}
rushly 2011-05-12
  • 打赏
  • 举报
回复
呵呵 点击修改按钮 请求url+用户名参数 一起提交不就可以了,,
如果含有中文 写设置下编码方式就可以了,,放范围对象里 也可以。
建议用户一登陆 就把它保存在范围对象中,后面跟他有关的操作就简单了。
还可以判断一些权限问题什么的。。。
仲兴轩 2011-05-12
  • 打赏
  • 举报
回复
最好建个对象来保存有用的信息, 当然也可以直接用那个user对象咯,
如果登录成功, 把该对象放在入session中,
页面上就可以直接取咯,

重要的一点是,
这好像不用JSP牛人就可以解决的问题呀
J5175 2011-05-12
  • 打赏
  • 举报
回复
我现在用Session保存后在JSP页面中能使用了,但是我不知道在另外一个Servlet(处理修改信息请求)中怎么使用,我想用String id= request.getAttribute("aid");但是还是不对

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧