`

${pageContext.request.contextPath}

阅读更多
[color=blue][/color]今天在写一个练习时,遇到一个路径问题,于是就去参考老师的代码,可是看见一个让我郁闷了半天的代码!

${pageContext.request.contextPath}


然后在网上找,更让我郁闷的事,TMD!网上“抄袭”的真多啊!而且扯了一大堆!关键的真没几个!让很郁闷!我心想:大哥们啊!你们贴在博客上的内容真的看懂了吗?我是看不懂!至少是说得我是很蒙!本来一句话可以搞定的事,偏偏啰嗦一大堆!而且贴的人还是很多!让我(是“狠”,不是“很”)郁闷!所以我只能靠自己理解了,现在明白了!在这里“啰嗦”一下我的观点!


${pageContext.request.contextPath} 等价于 <%request.getContextPath%>,或者可以说是<%request.getContextPath%>的EL版,<%request.getContextPath%>是JSP版!它们的意思就是取得当前项目名称(或者是--取出部署的应用程序名!这么说太官方了!试问有多少人知道“取出部署的应用程序名”的含义!不过我一看到这么说,头就大了!搞什么“孔乙己”啊!)
什么是当前的项目名称呢?
假定你的web application 名称为test,这个test就是当前的项目名称,不过你在浏览器中输入请求路径时,如:
http//:localhost:8080/test/hello.jsp
${pageContext.request.contextPath}或<%request.getContextPath%>就是从这个请求路径(URL)上截取(是截取)---->  /test   看清楚,前面是有"/",而这个“/”代表的是-->"http//:localhost:8080",看清楚这里是没有"/"的!
所以才有了网上那些文章写的,如果我们:
<form action="${pageContext.request.contextPath}/hello.jsp">这样写路径永远对,当然对了,因为你自己翻译${pageContext.request.contextPath}/hello.jsp其中的含义,不就是
http//:localhost:8080/test/hello.jsp  相当于你写了一全路径!当然前提是你的JSP页面等等必须放置的位置正确才可以---->所以才说明路径永远正确

为什么这么要做呢?因为学过一些MVC模式的程序员都知道,JSP的作用是用来显示的(表现的),其他的作用最好不要在这个页面上显示,尤其是Java代码!所以就用EL表达式来替代类似有“<%%>”这样的代码格式

最后我在说一句

用到${pageContext.request.contextPath}是在JSP页面上的!


分享到:
评论

相关推荐

    jsp页面中${pageContext.request.contextPath}介绍

    ${pageContext.request.contextPath}是JSP取得绝对路径的方法 例如:浏览器地址栏为”http://localhost:8080/test/index.jsp “ 那么:取出来的就是”http://localhost:8080/test”,简写为”/test” /test 等价于 ...

    JavaScript中${pageContext.request.contextPath}取值问题及解决方案

    在JSP里取${pageContext.request.contextPath},方式一是可以正常取到,但方式二却取到的是 字符“${pageContext.request.contextPath}” 方式一: [removed] var t = "${pageContext.request.contextPath}"; ...

    java web 登录验证码生成类

    ${pageContext.request.contextPath}/checkcode.jsp"/&gt; 另外在web.xml中配置验证码类的加载: &lt;servlet-name&gt;CheckCodeImage &lt;servlet-class&gt;com.netshop.common.util.CheckCodeImage&lt;/servlet-class&gt; ...

    jsp+mysql师生作业互动系统

    &lt;li&gt;&lt;a href="${pageContext.request.contextPath}/student!list"&gt;学生信息管理&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="${pageContext.request.contextPath}/exam!list"&gt;学生作业情况查询&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="${pageContext....

    jsp运行时的问题集合

    自己在实际开发中,发现并解决问题的总结。

    springMVC+mybatis

    ${pageContext.request.contextPath}/my/login" method="post"&gt; ${message } 邮箱: 密码: 登录"&gt; ${pageContext.request.contextPath}/my/regist"&gt;注册 ${pageContext.request....

    人脸识别研究综述

    人脸识别,用于进行人脸检测.二、javaEE框架学习笔记 2、的涵义: ...其中:“${pageContext.request.contextPath}”就是获取request的绝对路径,它的作用相当于“&lt;%=pageContext.request.contextPath%&gt;” 3、

    基于iframe实现类似于ajax的页面无刷新

    form id=”form0″ action=”${pageContext.request.contextPath}/news/baikeAdd.form” enctype=”multipart/form-data” method=”POST” target=”hidden_frame”&gt; … … &lt;/form&gt; &lt;iframe name=’...

    JSTL高级用法

    ${pageContext.request.contextPath} 服务的web application 的名称 ${pageContext.request.method} 取得HTTP 的方法(GET、POST) ${pageContext.request.protocol} 取得使用的协议(HTTP/1.1、HTTP/1.0) ${...

    struts2<s:if>使用心得

    href="${pageContext.request.contextPath}/ga/changeTaskAssigment.action?taskInstanceId=&lt;s:property value="id"/&gt;" &gt;我来处理)&lt;/s:if&gt; 受评对象准备评级资料"}'&gt; ${pageContext.request.contextPath}/ga/...

    ext时间控件,可以选择时分秒

    link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/extjs/pulgins/datetime/datetime.css" /&gt; [removed][removed] [removed][removed] [removed][removed] [removed]...

    kindEditor中关于上传处理

    link rel=”stylesheet” href=”${pageContext.request.contextPath}/common/kingeditor/themes/default/default.css”/&gt; &lt;link rel=”stylesheet” href=”${pageContext.request.contextPath}/common/...

    flash-swf格式计算器使用Object控件嵌入html即可使用(文件内有dom)

    codebase="${pageContext.request.contextPath }/common/plugins/calc/swflash.cab#version=6,0,0,0" id="BAPPFlash116526140886070277838"&gt; value="${pageContext.request.contextPath }/common/plugins/calc...

    轮播jar包

    link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/resources/css/login/login.css?version=20200311" /&gt; &lt;/head&gt; &lt;body&gt; &lt;li&gt;&lt;img src = "${pageContext....

    CONVERT函数方法大全_JAIMY.files ajax test url

    url:"${pageContext.request.contextPath}/module/updateModuleOrder.html", dateType:"json", data:"moduleId="+id+"&num="+demo1.value, type:"post", success:function(result,textStatus){ ...

    jQuery实现标签子元素的添加和赋值方法

    一、在jsp页面中定义&lt;select&gt;标签,如下: 科室: &lt;select class="dept-name-show" style="width: 70%;...var url = "${pageContext.request.contextPath}/getDepts.do";//请求路径 $(".dept-name-show").cli

    layui实现数据表格隐藏列的示例

    ,url:'${pageContext.request.contextPath}/findcustomers' ,cols: [[ {align:'center', title: '编号', sort: true,type:'numbers',width:100} ]] ,page: true }); 我们就会获得一列有序的数列(ps:这里的...

    springmvc接收ajax请求注意事项

    url: "${pageContext.request.contextPath}/txtAddAcc", dataType: "json", data: {"id": 1, "userName": "张三", "money": 123}, contentType: "application/json", success: function(data) { alert(data....

    HTML+CSS实现动态背景登录页面

    主要介绍了HTML+CSS实现动态背景登录页面的相关资料,需要的朋友可以参考下

Global site tag (gtag.js) - Google Analytics