标签:
1 <%@ page language="java" import="java.util.*" pageEncoding="GBK" contentType="text/html; charset=GBK"%> 2 <% 3 String path = request.getContextPath(); 4 String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; 5 %> 6 7 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 8 <html> 9 <head> 10 <base href="<%=basePath%>"> 11 12 <title>My JSP ‘regist.jsp‘ starting page</title> 13 14 <meta http-equiv="pragma" content="no-cache"> 15 <meta http-equiv="cache-control" content="no-cache"> 16 <meta http-equiv="expires" content="0"> 17 <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> 18 <meta http-equiv="description" content="This is my page"> 19 <!-- 20 <link rel="stylesheet" type="text/css" href="styles.css"> 21 --> 22 23 </head> 24 25 <body> 26 <form action="regist"> 27 登录名:<input type="text" name="name"/><br/> 28 密 码:<input type="password" name="password"/><br/> 29 <input type="submit" value="注册"/> 30 </form> 31 32 </body> 33 </html>
1 package servlet; 2 3 import java.io.IOException; 4 5 import javax.servlet.ServletException; 6 import javax.servlet.ServletRequest; 7 import javax.servlet.ServletResponse; 8 import javax.servlet.annotation.WebServlet; 9 import javax.servlet.http.HttpServlet; 10 11 import dao.userdata; 12 @WebServlet(urlPatterns={"/regist"}) 13 public class regist extends HttpServlet{ 14 userdata dao; 15 16 @Override 17 public void service(ServletRequest req, ServletResponse res) 18 throws ServletException, IOException { 19 req.setCharacterEncoding("GBK"); 20 String name=req.getParameter("name"); 21 String pass=req.getParameter("password"); 22 dao=userdata.getdao(); 23 dao.regist(name, pass); 24 req.getRequestDispatcher("login.jsp").forward(req, res); 25 } 26 27 28 29 }
标签:
原文地址:http://www.cnblogs.com/ztyy04126/p/4960561.html