1.创建一个Servlet,将其访问设置为*.do
<url-pattern>*.do</url-pattern>
2.一个请求url格式:http://localhost:8080/*.do(*代表自定义请求名)
3. Servlet获取请求路径名,根据路径名称执行相应的业务方法
public void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String uri = request.getRequestURI();
String path = uri.substring(uri.lastIndexOf("/"),uri.lastIndexOf("."));
response.setContentType("text/html;charset=utf-8");
PrintWriter out = response.getWriter();
/**根据用户提交的请求与对应的业务逻辑进行匹配判断*/
if(path.equals("/请求名")){
//do.....
}else if(path.equals("/请求名")){
//do.....
}
}
本文详细介绍了如何在Servlet中通过配置URL模式来处理自定义请求,并根据请求路径执行相应的业务方法。具体步骤包括创建Servlet、配置URL模式、实现请求处理逻辑。

被折叠的 条评论
为什么被折叠?



