[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页面上的!
分享到:
相关推荐
${pageContext.request.contextPath}是JSP取得绝对路径的方法 例如:浏览器地址栏为”http://localhost:8080/test/index.jsp “ 那么:取出来的就是”http://localhost:8080/test”,简写为”/test” /test 等价于 ...
在JSP里取${pageContext.request.contextPath},方式一是可以正常取到,但方式二却取到的是 字符“${pageContext.request.contextPath}” 方式一: [removed] var t = "${pageContext.request.contextPath}"; ...
${pageContext.request.contextPath}/checkcode.jsp"/> 另外在web.xml中配置验证码类的加载: <servlet-name>CheckCodeImage <servlet-class>com.netshop.common.util.CheckCodeImage</servlet-class> ...
<li><a href="${pageContext.request.contextPath}/student!list">学生信息管理</a></li> <li><a href="${pageContext.request.contextPath}/exam!list">学生作业情况查询</a></li> <li><a href="${pageContext....
自己在实际开发中,发现并解决问题的总结。
${pageContext.request.contextPath}/my/login" method="post"> ${message } 邮箱: 密码: 登录"> ${pageContext.request.contextPath}/my/regist">注册 ${pageContext.request....
人脸识别,用于进行人脸检测.二、javaEE框架学习笔记 2、的涵义: ...其中:“${pageContext.request.contextPath}”就是获取request的绝对路径,它的作用相当于“<%=pageContext.request.contextPath%>” 3、
form id=”form0″ action=”${pageContext.request.contextPath}/news/baikeAdd.form” enctype=”multipart/form-data” method=”POST” target=”hidden_frame”> … … </form> <iframe name=’...
${pageContext.request.contextPath} 服务的web application 的名称 ${pageContext.request.method} 取得HTTP 的方法(GET、POST) ${pageContext.request.protocol} 取得使用的协议(HTTP/1.1、HTTP/1.0) ${...
href="${pageContext.request.contextPath}/ga/changeTaskAssigment.action?taskInstanceId=<s:property value="id"/>" >我来处理)</s:if> 受评对象准备评级资料"}'> ${pageContext.request.contextPath}/ga/...
link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/extjs/pulgins/datetime/datetime.css" /> [removed][removed] [removed][removed] [removed][removed] [removed]...
link rel=”stylesheet” href=”${pageContext.request.contextPath}/common/kingeditor/themes/default/default.css”/> <link rel=”stylesheet” href=”${pageContext.request.contextPath}/common/...
codebase="${pageContext.request.contextPath }/common/plugins/calc/swflash.cab#version=6,0,0,0" id="BAPPFlash116526140886070277838"> value="${pageContext.request.contextPath }/common/plugins/calc...
link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/resources/css/login/login.css?version=20200311" /> </head> <body> <li><img src = "${pageContext....
url:"${pageContext.request.contextPath}/module/updateModuleOrder.html", dateType:"json", data:"moduleId="+id+"&num="+demo1.value, type:"post", success:function(result,textStatus){ ...
一、在jsp页面中定义<select>标签,如下: 科室: <select class="dept-name-show" style="width: 70%;...var url = "${pageContext.request.contextPath}/getDepts.do";//请求路径 $(".dept-name-show").cli
,url:'${pageContext.request.contextPath}/findcustomers' ,cols: [[ {align:'center', title: '编号', sort: true,type:'numbers',width:100} ]] ,page: true }); 我们就会获得一列有序的数列(ps:这里的...
url: "${pageContext.request.contextPath}/txtAddAcc", dataType: "json", data: {"id": 1, "userName": "张三", "money": 123}, contentType: "application/json", success: function(data) { alert(data....
主要介绍了HTML+CSS实现动态背景登录页面的相关资料,需要的朋友可以参考下