小程序交流群:528215729,加入和小伙伴们一起探讨开发疑难、运营idea吧

admin

admin

发表于 2018-05-13 14:11:03

摘要:第一个servlet小程序 (微信小程序开发 - 微信 小程序外包开发-微信小程序 开发教程-微信小程序开发者社区,尽在 www.mntuku.cn)

第一个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     @Override
13     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("服务器已经接收到get请求!!!!!!
"); 18 } 19 20 @Override 21 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>helloServletservlet-name>
 8         <servlet-class>com.fry.servlet.HelloServletservlet-class>
 9     servlet>
10     <servlet-mapping>
11         <servlet-name>helloServletservlet-name>
12         <url-pattern>/hiurl-pattern>
13     servlet-mapping>
14 web-app>

 目录结构

 

22阅读 | 0评论
你的回应