请求servlet的web.xml配置说明
来源:互联网 发布:百度seo一本通pdf下载 编辑:程序博客网 时间:2024/05/16 08:27
要请求servlet,必须要在web.xml文件里面配置servlet的映射路径,具体如下:
<servlet> <servlet-name>servletDemo</servlet-name> <servlet-class>com.servlet.servletDemo</servlet-class> </servlet> <servlet-mapping> <servlet-name>servletDemo</servlet-name> <url-pattern>/servletDemo/aaa</url-pattern> </servlet-mapping>
配置文件详解如下:
< servlet-mapping >里面的 < url-pattern >是请求路径,服务器根据这个路径在< servlet-mapping >里面找到这个路径对应的< servlet-name >,再在< servlet > 里面根据其servlet-name找到这个请求路径对应的类。
详细用例如下:
jsp页面:
<form action="servletDemo/aaa" method="post"> <input type="text" name="name"> <input type="submit" value="提交"> </form>
servlet:
package com.servlet;import java.io.IOException;import javax.servlet.ServletException;import javax.servlet.annotation.WebServlet;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;@WebServlet("/servletDemo")public class servletDemo extends HttpServlet { private static final long serialVersionUID = 1L; public servletDemo() { // TODO Auto-generated constructor stub } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub String name = request.getParameter("name"); System.out.println(name); }}
这里可以看出,from发起请求,路径“servletDemo/aaa”,服务器通过请求获取到该路径对应的servlet所在类,把改请求发送该路径对于的类处理了。
阅读全文
0 0
- 请求servlet的web.xml配置说明
- web.xml关于servlet配置中url-pattern的说明
- tomcat servlet与web.xml的配置说明一
- tomcat servlet与web.xml的配置说明二
- servlet请求处理 web.xml配置
- servlet的web.xml配置
- servlet的web.xml配置
- Servlet的web.xml配置
- Servlet的生命周期及其常用覆盖方法的说明 以及在web.xml中配置servlet的属性说明
- Spring-web中的web.xml为Servlet提供的配置选项说明
- web.xml配置Servlet
- servlet web.xml配置
- web.xml配置servlet
- web.xml 配置-servlet
- servlet的web.xml的配置信息
- web.xml配置说明
- web.xml配置说明
- web.xml配置说明
- 快速排序
- DEEP LEARNING第五章
- Servlet(cookie的生存时间与请求路径)
- Codeforces Round #284 (Div. 2) D. Name That Tune 概率dp
- 努力做一个灵魂画师、Affinity Designer使用(一)
- 请求servlet的web.xml配置说明
- 并发基础_15_并发_线程池(ThreadPoolExecutor)
- Javascript学习之H5自动重连技术实现方法详解
- Debian/Ubuntu应用程序开机自启动
- Matlab 使用技巧
- 在学习GraytHatPython构建Window调试器过程中遇到的问题
- 1002. 后缀表达式计算
- org.apache.ibatis.binding.BindingException: Invalid bound statement (not found) 引发的血案
- android监听View加载完成