String path = request.getContextPath();这段什么用

<% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %>

答:


这样的代码是在jsp里出现的吧, 那么他的含义就是为了得到一个路径, 做动态网站时,需要提交form表单 在表单的action里面就会这样来写 action="<%=path %>/add.do" 这样来提交到相应的servlet中去,这样可以避免路径的错误,而采用这样的相对路径会更好些 

答:

request.getContextPath()应该是得到项目的名字,如果项目为根目录,则得到一个"",即空的字条串, 如果项目为abc, <%=request.getContextPath()% >/ 将得到abc/,服务器端的路径则会自动加上
posted @ 2014-05-01 09:36  成风魄郎  阅读(2242)  评论(0编辑  收藏  举报