JSP>>XML>>SERVLET(java)

  • JSP:

 

 1 <%@page import="com.volkswagenag.iportal.model.comparator.user.UserNameComparator"%>
 2 <%@page import="com.liferay.portal.model.User"%>
 3 <%@page import="com.sun.org.apache.bcel.internal.generic.NEW"%>
 4 <%@page import="webpackage.testlogin"%>
 5 <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
 6     pageEncoding="ISO-8859-1"%>
 7 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 8 <html>
 9 <head>
10 <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
11 <title>Insert title here</title>
12 </head>
13 <body>
14 
15     <form method="post" action="hello.do">
16     Username:
17     <input type="text" name="username"><br><br>
18     Password:
19     <input type="password" name="password"><br><br>
20     <center>
21         <input type="submit" value="Login" name="login">
22     </center>
23 </form>
24         
25 </body>
26 </html>

 

  • XML

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
  <display-name></display-name>
  <servlet>
    <servlet-name>ser</servlet-name>
    <servlet-class>webpackage.ser</servlet-class>
   </servlet>
   <servlet-mapping>
    <servlet-name>ser</servlet-name>
    <url-pattern>/hello.do</url-pattern>
  </servlet-mapping>
</web-app>

 

  • Servlet
 1 package webpackage;
 2 
 3 import java.io.IOException;
 4 import java.io.PrintWriter;
 5 
 6 import javax.servlet.ServletException;
 7 import javax.servlet.annotation.WebServlet;
 8 import javax.servlet.http.HttpServlet;
 9 import javax.servlet.http.HttpServletRequest;
10 import javax.servlet.http.HttpServletResponse;
11 
12 /**
13  * Servlet implementation class ser
14  */
15 @WebServlet("/ser")
16 public class ser extends HttpServlet {
17     private static final long serialVersionUID = 1L;
18        
19    
20     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
21         // TODO Auto-generated method stub
22         response.setContentType("text/html");
23         PrintWriter out = response.getWriter();
24         String u = request.getParameter("username");
25         String p = request.getParameter("password");
26         out.print(u);
27         out.print(p);
28     }
29 
30 
31 }

posted on 2017-01-20 16:53  lonske  阅读(1555)  评论(0编辑  收藏  举报