Servlet总结1

---恢复内容开始---

 

 

 

 

package com.werner.app;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class ServletDemo1 extends HttpServlet {
       @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html");
PrintWriter out = resp.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.flush();
out.close();
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
 resp.setContentType("text/html");
 PrintWriter out = resp.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 POST method");
  out.println("  </BODY>");
 out.println("</HTML>");
 out.flush();
 out.close();

    }
}

 

 

 

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
  <display-name>Archetype Created Web Application</display-name>
  <servlet>
    <servlet-name>ServletDemo1</servlet-name>
    <servlet-class>com.werner.app.ServletDemo1</servlet-class>
    <init-param>
      <param-name>name</param-name>
      <param-value>gacl</param-value>
    </init-param>
    <init-param>
      <param-name>password</param-name>
      <param-value>123</param-value>
    </init-param>
    <init-param>
      <param-name>charset</param-name>
      <param-value>utf-8</param-value>
    </init-param>
  </servlet>
  <servlet-mapping>
    <servlet-name>ServletDemo1</servlet-name>
    <url-pattern>/servlet/ServletDemo1</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>ServletDemo1</servlet-name>
    <url-pattern>/1.htm</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>ServletDemo1</servlet-name>
    <url-pattern>/2.jsp</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>ServletDemo1</servlet-name>
    <url-pattern>/3.php</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>ServletDemo1</servlet-name>
    <url-pattern>/4.ASPX</url-pattern>
  </servlet-mapping>

</web-app>

 

 

 

---恢复内容结束---

posted @ 2017-09-08 01:28  友情天  阅读(123)  评论(0编辑  收藏  举报