当前位置: 首页 > news >正文

响应式网站建站价格seo关键词外包

响应式网站建站价格,seo关键词外包,莱州网页,企业建筑网站版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。 本文链接: https://blog.csdn.net/qq_27770257/article/details/79438987 最近对于request中的几种“路径”有点混淆,查…
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/qq_27770257/article/details/79438987

最近对于request中的几种“路径”有点混淆,查找网上资源都没有很好的总结,希望此文章能够帮助我理解一下这几种“路径”。
+++++++++++++++++++++++++++++++++++++++++++++++++
本文章主要讨论以下几种request获取路径的方法:

request.getServletPath()
request.getPathInfo()
request.getContextPath()
request.getRequestURI()
request.getRequestURL()
request.getServletContext().getRealPath()
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

以一个简单的例子说明:
web.xml配置(注意此处的url-pattern项)

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"><display-name>aab</display-name><welcome-file-list><welcome-file>a.jsp</welcome-file></welcome-file-list><servlet><servlet-name>test</servlet-name><servlet-class>com.java.test.TestServlet</servlet-class></servlet><servlet-mapping><servlet-name>test</servlet-name><url-pattern>/*</url-pattern><!-- 注意此处 --></servlet-mapping></web-app>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

TestServlet.java文件:

package com.java.test;import java.io.IOException;import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;public class TestServlet extends HttpServlet{@Overrideprotected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {this.doPost(req, resp);}@Overrideprotected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {System.out.println("servletPath:"+req.getServletPath());System.out.println("contextPath:"+req.getContextPath());System.out.println("contextPath2:"+req.getServletContext().getContextPath());System.out.println("pageInfo:"+req.getPathInfo());System.out.println("uri:"+req.getRequestURI());System.out.println("url:"+req.getRequestURL());System.out.println("realPath:"+req.getServletContext().getRealPath("/"));}}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28

此时请求http://localhost:8080/testweb (url-pattern=/*)
打印出来的值为:

servletPath:
contextPath:/testweb
contextPath2:/testweb
pageInfo:null
uri:/testweb
url:http://localhost:8080/testweb
realPath:G:\java\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\testweb\
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

请求http://localhost:8080/testweb/abc 打印的值为:

servletPath:
contextPath:/testweb
contextPath2:/testweb
pageInfo:/abc
uri:/testweb/abc
url:http://localhost:8080/testweb/abc
realPath:G:\java\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\testweb\
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

当我们修改web.xml为如下时(注意url-pattern的改变):

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"><display-name>aab</display-name><welcome-file-list><welcome-file>a.jsp</welcome-file></welcome-file-list><servlet><servlet-name>test</servlet-name><servlet-class>com.java.test.TestServlet</servlet-class></servlet><servlet-mapping><servlet-name>test</servlet-name><url-pattern>/abc/def/*</url-pattern><!-- 注意此处 --></servlet-mapping></web-app>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

请求http://localhost:8080/testweb/abc/def/ghi/test.html (url-pattern=/abc/def/*)
打印的值为:

servletPath:/abc/def
contextPath:/testweb
contextPath2:/testweb
pageInfo:/ghi/test.html
uri:/testweb/abc/def/ghi/test.html
url:http://localhost:8080/testweb/abc/def/ghi/test.html
realPath:G:\java\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\testweb\
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

通过观察打印结果,我们可以总结:
1. getServletPath():获取能够与“url-pattern”中匹配的路径,注意是完全匹配的部分,*的部分不包括。
2. getPageInfo():与getServletPath()获取的路径互补,能够得到的是“url-pattern”中*d的路径部分
3. getContextPath():获取项目的根路径
4. getRequestURI:获取根路径到地址结尾
5. getRequestURL:获取请求的地址链接(浏览器中输入的地址)
6. getServletContext().getRealPath(“/”):获取“/”在机器中的实际地址
7. getScheme():获取的是使用的协议(http 或https)
8. getProtocol():获取的是协议的名称(HTTP/1.11)
9. getServerName():获取的是域名(xxx.com)
10. getLocalName:获取到的是IP


以上

http://www.ds6.com.cn/news/67176.html

相关文章:

  • 汕头网站建设优化抖音关键词搜索排名收费
  • 眉山手机网站建设网站seo优化多少钱
  • 公司让我做网站负责人百度广告屏蔽
  • 国外的网站建设seo快排优化
  • 周村网站制作哪家好上海免费关键词排名优化
  • 收费网站有哪些台州专业关键词优化
  • 专业html5网站建设武汉网站建设公司
  • 青岛手机网站建设app开发公司推荐
  • 做汇算清缴在哪个网站下百度推广登录入口官网
  • 企业建设网站的作用大不大seo外包优化公司
  • 马克斯网站建设seo建站技巧
  • 做网站需要懂什么软件手机百度账号申请注册
  • 广安哪里有做网站的公司图片外链上传网站
  • 网站上的3d产品展示怎么做seo推广小分享
  • 做营销网站视频安徽网站开发哪家好
  • 网站改造app优化方案
  • 仙居做网站公司班级优化大师免费下载app
  • 大型网站都怎么做推广互联网媒体推广
  • 做网站视频教学windows7系统优化工具
  • 石家庄做网站哪家好2024年2月疫情又开始了吗
  • 天津电商网站开发百度热搜关键词
  • 台州企业网站seo河北seo关键词排名优化
  • 东莞企业官方网站建设seo常用工具网站
  • 西班牙外贸网站重庆优化seo
  • 洞口做网站的公司1688的网站特色
  • 网站适配移动端和PC端安卓优化大师下载安装
  • wordpress github评论班级优化大师官网下载
  • wordpress添加动漫人物谷歌seo是指什么意思
  • 做网站客户要求分期郑州互联网公司排名
  • 可以做短信炸弹的网站23岁老牌网站