<%@ 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();
}
}
}
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();
}
}
}
解决方案 »
- 关于庖丁解牛中文分词
- 求推荐考软件设计相关的证书
- java.sql.SQLException: No suitable driver found for oracle:jdbc:thin:
- 关于html级联问题
- 求知识,有没有什么方法能获得ActionForm中get方法个数的??
- java 浏览器访问问题 网址过滤
- struts2中的验证框架和数据库不为空字段问题
- Hibernate中HQL语句中使用函数问题?
- 怎样生成永不重复的8为数字id
- 我想实现数组的倒序,然后这个运行控制台怎么没反应
- struts hidden的问题
- Join ftech的异常 org.hibernate.hql.antlr.HqlBaseParser.recover
方法二:在jsp页面上写${aid }
或
${aid}
如果登录成功, 把该对象放在入session中,
页面上就可以直接取咯,重要的一点是,
这好像不用JSP牛人就可以解决的问题呀
如果含有中文 写设置下编码方式就可以了,,放范围对象里 也可以。
建议用户一登陆 就把它保存在范围对象中,后面跟他有关的操作就简单了。
还可以判断一些权限问题什么的
或者直接用${aid}
你这里要用 String id= (String)request.getSession().getAttribute("aid")
String id=(String)request.getSession().getAttribute("aid");返回字符串的ID
不管你在哪个servlet中,都能获取到自己session中的用户名