JavaWeb学习总结8.13

《Servlet学习》

在这里插入图片描述
已经学习了前三种接口。
也写了一个便于巩固的小网页

index.jsp

<%--
  Created by IntelliJ IDEA.
  User: ZLB
  Date: 2019/8/13
  Time: 19:05
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
  <meta charset="utf-8">
  <title>WebText</title>
  <style type="text/css">
    body,td,th {
      font-family: Gotham, "Helvetica Neue", Helvetica, Arial, sans-serif;
      color: #E21115;
    }
    body {
      background-color: #BAB1B2;
    }
  </style>
</head>

<body>
<p>这是一个DW制作的前端网页显示~
</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<form action="Servlet" method="post" name="form1" id="form1">
  <em>
    <input type="submit" name="submit" id="submit" value="提交至服务器端">
  </em>
</form>
</body>
</html>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
         version="4.0">
    <servlet>
        <servlet-name>a</servlet-name>
        <servlet-class>Servlet</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>a</servlet-name>
        <url-pattern>/Servlet</url-pattern>
    </servlet-mapping>

    <context-param>
    <param-name>baidu</param-name>
    <param-value>www.baidu.com</param-value>
    </context-param>

    <context-param>
        <param-name>qqemil</param-name>
        <param-value>1059954375@qq.com</param-value>
    </context-param>
</web-app>

Servlet.java

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 Servlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("doGer~");

//        PrintWriter outt = resp.getWriter();
//        outt.print("<h2>当前Web应用的所有初始化参数为:baidu  qqemil");
//        outt.print("baidu  参数值为 "+super.getServletContext().getInitParameter("baidu"));
//        outt.print("qqemil 参数值为 "+super.getServletContext().getInitParameter("qqemil"));
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("doPost~");
    }

    @Override
    public void init() throws ServletException {
        System.out.println("出生了~");
    }

    @Override
    public void destroy() {
        System.out.println("死掉了~");
    }
}

在这里插入图片描述
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值