servlet 转发请求

<%@ page language="java" pageEncoding="gb2312"%>

<html>
<head>

<title>注册用户</title>

</head>

<body>
<form name="form1" action="zhuce" method="post">
<table width="100%" border="0"">
<tr>
<td>新用户注册:</td>

</tr>
<hr align="center">
<tr>
<td width="17%">请输入帐号:</td>
<td width="83%">
<input name="username1" type="text" id="username" size="15" maxlength="20">
</td>
</tr>
</table>
<hr align="center">
<table width="100%" border="0"> 
<tr>
<td width="17%">请输入用户名:</td>
<td width="83%">
<input name="username2" type="text" id="username" size="15" maxlength="20">
</td>
</tr>
</table>
<hr align="center">
<table width="100%" border="0"> 
<tr>
<td width="17%">请输入密码:</td>
<td width="83%">
<input name="pwd1" type="password" size="15" maxlength="20">
</td>
</tr>
</table>
<hr align="center">
<table width="100%" border="0"> 
<tr>
<td width="17%"> 密码确认:</td>
<td width="83%">
<input name="pwd2" type="password" size="15" maxlength="20">
</td>
</tr>
</table>
<hr align="center">
<table width="100%" border="0">
<tr>
<td width="17%">请输入E-MAIL:</td>
<td width="83%">
<input name="username3" type="text" id="username" size="25" maxlength="20">
</td>
</tr>
</table>
<hr align="center">
<table width="100%" border="0"> 
<tr>
<td width="17%">请输入常用电话:</td>
<td width="83%">
<input name="username4" type="text" id="username" size="15" maxlength="20">
</td>
</tr>
</table>
<hr align="center">
<table width="100%" border="0"> 
<tr>
<td width="17%">请输入收货地址:</td>
<td width="83%">
<input name="username5" type="text" id="username" size="50" maxlength="20">
</td>
</tr>
</table>
<hr align="center">
<table width="100%" border="0"> 
<tr>
<td width="17%">请输入邮编:</td>
<td width="87%">
<input name="username6" type="text" id="username" size="15" maxlength="20">
</td>
</tr>
</table>
<hr align="center">
<table align="center"> 
<tr>
<td>
<input name="zhuce1" type="button"value="注册" onClick="zhuce()">
<input name="zhuce2" type="button" value="取消注册">
</td>
</tr>

</table>
</form>

</body>
</html>
------------------------------------

package com.xaccp.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.xaccp.daoImpl.UsersDaoImpl;
import com.xaccp.entity.Users;

public class LoginServlet extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doPost(request, response);
}

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String userName=request.getParameter("userName");
String password=request.getParameter("password");

Users u=new Users();
u.setUserName(userName);
u.setPassword(password);

UsersDaoImpl dao=new UsersDaoImpl();
if(dao.checkLogin(u))
{
Users LoginUser=dao.findUsersByName(userName);
HttpSession session=request.getSession();
session.setAttribute("LoginUser", LoginUser);
response.sendRedirect("/addressBook/SelectServlet");
}
else
{
response.sendRedirect("/addressBook/index.jsp");
}
}

}

上面这上登录验证的Servlet

下面上配置web.xml配置文件

<servlet>
<description>This is the description of my J2EE component</description>
<display-name>This is the display name of my J2EE component</display-name>
<servlet-name>LoginServlet</servlet-name>
<servlet-class>com.xaccp.servlet.LoginServlet</servlet-class>
</servlet>

下满上登录页面的form

<form name="login" action="loginServlet" method="post" οnsubmit="return checkLongin()">

<TABLE width="100%"
style="cellpadding: 0px; cellspacing: 0px; margin-top: 0px; margin-Left: 0px"
style="table-layout: fixed;WORD-BREAK: break-all; WORD-WRAP: break-word">
<TR>
<TD style="color:#4c4743;line-height:160%;" valign="top"
width="30%">用户名:</TD>
<TD style="color:#4c4743;line-height:160%;" valign="top"><input
type="text" name="userName" value="<%=userName %>"/></TD>
<TD style="color:#4c4743;line-height:160%;"><a href="register.jsp">注册</a></TD>

</TR>
<TR>
<TD style="color:#4c4743;line-height:160%;" valign="top"
width="30%">密  码</TD>
<TD style="color:#4c4743;line-height:160%;" valign="top"><input
type="password" name="password" /></TD>
</TR>
<TR>
<TD style="color:#4c4743;line-height:160%;" valign="top"
width="30%"><input type="submit" value="提交" /></TD>
<TD style="color:#4c4743;line-height:160%;" valign="top"><input
type="reset" value="重置" /></TD>
</TR>
</TABLE>
</td>
<td width="47" valign="top" background="image/flower/m_bg.jpg"> </td>
</tr>
</table>

</form>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值