1.servlet
用来开发动态web 资源的技术
2.HelloServlet() 用这个来写网站
3.构造方法(实例化) ----》init (初始化) ----》service(具体业务)----》
destory(销毁)
4.新建servlet方式
–1.implements Servlet
–2.extends GenericServlet
–3.extends HttpServlet
5.get post
post 表单
get url get请求
6.http 2种请求 get post
7.servlet
1.helloservlet extend httpservlet
2.doget (“12345”)
3.web.xml
zhuce
com.zhongruan.servlet.helloservlet
zhuce
/zhuce
先创建一个项目,并在目录下创建这些文件:
在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>HelloServlet</servlet-name>
<servlet-class>com.zhongruan.serviet.HelloServiet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloServlet</servlet-name>
<url-pattern>/hello</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>zhuce</servlet-name>
<servlet-class>com.zhongruan.serviet.ZhuCe</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>zhuce</servlet-name>
<url-pattern>/zhuce</url-pattern>
</servlet-mapping>
</web-app>
在zhuCe中输入如下代码:
package com.zhongruan.serviet;
import com.sun.net.httpserver.HttpServer;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
public class ZhuCe extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.getWriter().write("hello");
}
}
运行结果如下: