《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> </p>
<p> </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("死掉了~");
}
}