• 第一个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     @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("<strong>服务器已经接收到get请求!!!!!!</strong><br>");
    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>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>

     目录结构

  • 相关阅读:
    第二十二篇、服务器返回的数据转成模型
    第二十一篇、广告轮播器(支持循环滚动)
    【转】android应用程序的安装方式与原理
    【转】Android中处理崩溃异常
    android在Data目录内置可删除的APP
    Ubuntu下修改system.img 解包system.img、打包system.img
    Android studio打包APK混淆配置
    Android获取焦点所在控件
    Android根据APP包名启动应用
    Android自动更新安装后显示‘完成’‘打开’按钮
  • 原文地址:https://www.cnblogs.com/Renyi-Fan/p/7761796.html
Copyright © 2020-2023  润新知