我在处理登录信息的check_login.jsp页面上需要加string path request.getcontextpath吗?

有没有人在啊,想请分析下,我在处理登录信息的check_login.jsp页面上需要加string path request.getcontextpath吗?
最新回答
落日在山时

2024-05-30 06:56:00

看你自己的需要,用不到也可以不写
我们一般会在jsp页面写上去
request.getContextPath(); // 应用的web目录的名称(你的项目名称)
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
为什么要写,看看下面的使用
<link rel="stylesheet" type="text/css" href="<%=path %>/res/common/css/common.css"/>
<form id="pageForm" class="recommend_list" action="<%=path %>/getComprehensiveTemplateListByPage.action" method="post" >
这些都是用到了path,不用也可以但是你需要将自己的项目名称放上去
<link rel="stylesheet" type="text/css" href="/项目名称/res/common/css/common.css"/>
页面多的话还可以考虑把
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
写在一个单独的页面上,然后其他页面引用这个单独的页面,这样你就不用每个页面都写了