Java Servlet使用
Servlet作用:是用来处理请求和发送响应。使用:创建MyServlet,继承自HttpServletpublic class MyServlet extends HttpServlet {@Overrideprotected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ...
·
Servlet作用:是用来处理请求和发送响应。
使用:
- 创建MyServlet,继承自HttpServlet
public class MyServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
System.out.print("Get请求\n");
}
}
- 配置web.xml
<servlet>
<!--servlet名字-->
<servlet-name>MyServlet</servlet-name>
<!--servlet文件路径-->
<servlet-class>yang.shuai.cn.MyServlet</servlet-class>
</servlet>
<servlet-mapping>
<!--servlet名字-->
<servlet-name>MyServlet</servlet-name>
<!--url填写后缀-->
<url-pattern>/MyServlet</url-pattern>
</servlet-mapping>
- 启动服务器,浏览器输入http://localhost:8080/MyServlet
更多推荐
已为社区贡献1条内容
所有评论(0)