第一個servlet小程式,servlet小程式

來源:互聯網
上載者:User

第一個servlet小程式,servlet小程式
第一個servlet小程式

com.fry.servlet.HelloServlet

 1 package com.fry.servlet; 2  3 import javax.servlet.ServletException; 4 import javax.servlet.http.HttpServlet; 5 import javax.servlet.http.HttpServletRequest; 6 import javax.servlet.http.HttpServletResponse; 7 import java.io.IOException; 8 import java.io.PrintWriter; 9 10 public class HelloServlet extends HttpServlet {11 12     @Override13     protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {14         System.out.println("接收到get請求!!!");15         PrintWriter out=resp.getWriter();16         resp.setContentType("text/html;charset=utf-8");17         out.println("<strong>伺服器已經接收到get請求!!!!!!</strong><br>");18     }19 20     @Override21     protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {22         System.out.println("接收到post請求!!!");23     }24 }

 

index.jsp

 1 <%-- 2   Created by IntelliJ IDEA. 3   User: user 4   Date: 2017/10/31 5   Time: 13:46 6   To change this template use File | Settings | File Templates. 7 --%> 8 <%@ page contentType="text/html;charset=UTF-8" language="java" %> 9 <html>10   <head>11     <title>$Title$</title>12   </head>13   <body>14   歡迎訪問我的第一個JSP。<br>15   <a href="hi">get請求</a>16   </body>17 </html>

WEB-INF/web.xml

 1 <?xml version="1.0" encoding="UTF-8"?> 2 <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" 3          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4          xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" 5          version="3.1"> 6     <servlet> 7         <servlet-name>helloServlet</servlet-name> 8         <servlet-class>com.fry.servlet.HelloServlet</servlet-class> 9     </servlet>10     <servlet-mapping>11         <servlet-name>helloServlet</servlet-name>12         <url-pattern>/hi</url-pattern>13     </servlet-mapping>14 </web-app>

 目錄結構

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.