我把它粘下来了大家帮找找
package 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 bbsBean.User;
import userImp.userimp;
public class Registuser extends HttpServlet {
/**
* Constructor of the object.
*/
public Registuser() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
request.setCharacterEncoding("GBK");
PrintWriter out = response.getWriter();
out
.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
out.print(" This is ");
out.print(this.getClass());
out.println(", using the GET method");
out.println(" </BODY>");
out.println("</HTML>");
out.close();
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
request.setCharacterEncoding("GBK");
PrintWriter out = response.getWriter();
String username=request.getParameter("uid");
String password=request.getParameter("password");
String email=request.getParameter("email");
String nickname=request.getParameter("nickname");
int degree=1;
String registerdate = "sysdate";
User user=new User();
user.setName(username);
user.setPassword(password);
user.setEmail(email);
user.setNickname(nickname);
user.setDegree(degree);
user.setRegisterdate(registerdate);
userimp uimp=new userimp();
try
{
if(uimp.userAdd(user))
{
request.setAttribute("smsg", "注册成功");
request.setAttribute("suc", "注册成功");
request.setAttribute("sback", "userlogin.jsp");
//response.sendRedirect("Success.jsp");
request.getRequestDispatcher("Success.jsp").forward(request, response);
}
else
{
}
}
catch(Exception ex)
{
System.out.println(ex.getMessage());
}
out.close();
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occure
*/
public void init() throws ServletException {
// Put your code here
}
}
jsp页
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title><%
request.setCharacterEncoding("GBK");
if(request.getAttribute("smsg")!=null)
{
String smsg=request.getAttribute("smsg").toString();
out.print(smsg);
}
else
out.print("成功页");
%></title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<h1 align="center">恭喜、<%=request.getAttribute("suc")==null?"恭喜":request.getAttribute("suc").toString()%></h1>
<hr color="grey" width="100%">
<p align="center"><a href=<%=request.getAttribute("sback")==null?"#":request.getAttribute("sback").toString()%>>返回</a> </p>
</body>
</html>