【Java开源代码栏目提醒】:网学会员Java开源代码为您提供WebUtils.java参考,解决您在WebUtils.java学习中工作中的难题,参考学习。
package com.cownew.PIS.framework.web.helper;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.PageContext;
public class WebUtils
{
/**
* 从pageContext得到部署路径
* @param pageContext
* @return
*/
public static String getContextPath(PageContext pageContext)
{
HttpServletRequest request = (HttpServletRequest) pageContext
.getRequest();
return request.getContextPath();
}
/**
* 得到path的相对于部署路径的绝对路径
* @param request
* @param response
* @param path
* @return
*/
public static String getAbsoluteURL(HttpServletRequest request,
HttpServletResponse response, String path)
{
String contextPath = request.getContextPath();
if (!path.startsWith("/"))
{
path = "/" + path;
}
return response.encodeURL(contextPath + path);
}
/**
* 得到path的相对于部署路径的绝对路径
* @param pageContext
* @param path
* @return
*/
public static String getAbsoluteURL(PageContext pageContext, String path)
{
HttpServletRequest request = (HttpServletRequest) pageContext
.getRequest();
HttpServletResponse reponse = (HttpServletResponse) pageContext
.getResponse();
return getAbsoluteURL(request, reponse, path);
}
}
上一篇:
WebSphereTransactionManagerLookup.java
下一篇:
关于大学英语教学