本文整理汇总了Java中javax.servlet.http.HttpServletRequest.getServletPath方法的典型用法代码示例。如果您正苦于以下问题:Java HttpServletRequest.getServletPath方法的具体用法?Java HttpServletRequest.getServletPath怎么用?Java HttpServletRequest.getServletPath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.servlet.http.HttpServletRequest
的用法示例。
在下文中一共展示了HttpServletRequest.getServletPath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doFilter
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletRequest hsrq = (HttpServletRequest) request;
HttpServletResponse hsrp = (HttpServletResponse) response;
String clientType = hsrq.getParameter("clientType");
if ("WORD".equals(clientType)) {
chain.doFilter(request, response);
} else {
SessionUser person = null;
String reqPage = hsrq.getServletPath();
if (!reqPage.trim().equals("/login.do") && !reqPage.trim().equals("/logout.do")
) {
person = (SessionUser) hsrq.getSession().getAttribute(SysConstants.SESSION_USER_KEY);
if (person == null) {
hsrp.sendRedirect("login.do");
return;
}
}
chain.doFilter(request, response);
}
}
示例2: getPath
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
private String getPath(final HttpServletRequest request) {
String servletPath;
String pathInfo;
if (request.getDispatcherType() == DispatcherType.INCLUDE && request.getAttribute(RequestDispatcher.INCLUDE_REQUEST_URI) != null) {
pathInfo = (String) request.getAttribute(RequestDispatcher.INCLUDE_PATH_INFO);
servletPath = (String) request.getAttribute(RequestDispatcher.INCLUDE_SERVLET_PATH);
} else {
pathInfo = request.getPathInfo();
servletPath = request.getServletPath();
}
String result = pathInfo;
if (result == null) {
result = CanonicalPathUtils.canonicalize(servletPath);
} else if (resolveAgainstContextRoot) {
result = servletPath + CanonicalPathUtils.canonicalize(pathInfo);
} else {
result = CanonicalPathUtils.canonicalize(result);
}
if ((result == null) || (result.isEmpty())) {
result = "/";
}
return result;
}
示例3: getWholeUrl
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
/**
* 获取完整的url,包括域名端口等
* @return
*/
public static String getWholeUrl(HttpServletRequest request){
String servername =request.getServerName();
String path = request.getServletPath();
int port = request.getServerPort();
String portstr="";
if(port!=80){
portstr=":"+port;
}
String contextPath = request.getContextPath();
if(contextPath.equals("/")){
contextPath="";
}
String url = "http://"+servername+portstr+contextPath+"/"+path;
return url;
}
示例4: doFilter
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@Override
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
HttpServletRequest httpRequest = (HttpServletRequest) request;
Pattern pattern = Pattern.compile(urlPattern, Pattern.CASE_INSENSITIVE);
String url = httpRequest.getServletPath();
Matcher matcher = pattern.matcher(url);
if (matcher.matches()) {
String version = matcher.group(1);
String serviceName = matcher.group(2);
String portType = matcher.group(3);
httpRequest.setAttribute(WSDLDeliverServlet.VERSION, version);
httpRequest.setAttribute(WSDLDeliverServlet.SERVICE_NAME,
serviceName);
httpRequest.setAttribute(WSDLDeliverServlet.PORT_TYPE, portType);
String fileType = request.getParameterNames().nextElement();
httpRequest.setAttribute(WSDLDeliverServlet.FILE_TYPE, fileType);
String tenantId = httpRequest.getParameter(tenantIdParam);
httpRequest.setAttribute(WSDLDeliverServlet.TENANT_ID, tenantId);
httpRequest.getRequestDispatcher(servletUrl).forward(httpRequest,
response);
}
return;
}
示例5: generateWsdl
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
protected String generateWsdl(HttpServletRequest request) throws EngineException {
Engine.logEngine.debug("(WebServiceServlet) WSDL required");
String servletPath = request.getServletPath();
Engine.logEngine.debug("(WebServiceServlet) Servlet path: " + servletPath);
String servletURI = HttpUtils.originalRequestURL(request);
Engine.logEngine.debug("(WebServiceServlet) Servlet uri: " + servletURI);
try {
int projectNameStartIndex = servletPath.indexOf("/projects/") + 10;
int slashIndex = servletPath.indexOf("/", projectNameStartIndex);
String projectName = servletPath.substring(projectNameStartIndex, slashIndex);
Engine.logEngine.debug("(WebServiceServlet) Project name: " + projectName);
if (servletPath.endsWith(".wsl") || servletPath.endsWith(".ws") || servletPath.endsWith(".wsr")) {
return generateWsdlForDocLiteral(servletURI, projectName);
}
throw new EngineException("Unhandled SOAP method (RPC or literal accepted)");
}
catch(StringIndexOutOfBoundsException e) {
throw new EngineException("Unable to find the project name into the provided URL (\"" + servletPath + "\").");
}
}
示例6: doFilter
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
/**
* @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain)
*/
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
// TODO Auto-generated method stub
// place your code here
// pass the request along the filter chain
HttpServletRequest hsRequest = (HttpServletRequest) request;
HttpServletResponse hsResponse=(HttpServletResponse)response;
//用于获取当前页面的路径
String servletPath = hsRequest.getServletPath();
//获取session储存的admin信息
Admin admin = (Admin)hsRequest.getSession().getAttribute("loginedAdmin");
List<GameCompleteServer> list = new GameServerListDao().findGameServers();
if("/adminjsp/server.jsp".equals(servletPath)) {
if(null != admin) {
if(null != list && list.size() > 0
&& null == hsRequest.getSession().getAttribute("gameServerList"))
hsRequest.getSession().setAttribute("gameServerList", list);
System.out.println(list.size());
}
} else if("/userjsp/login.jsp".equals(servletPath)) {
if(null != list && list.size() > 0
&& null == hsRequest.getSession().getAttribute("gameServerList")) {
hsRequest.getSession().setAttribute("gameServerList", list);
System.out.println(list.size());
}
}
chain.doFilter(request, response);
}
示例7: doFilter
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@Override
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest)req;
HttpServletResponse response = (HttpServletResponse)resp;
String path = request.getContextPath() + request.getServletPath() + request.getPathInfo();
if (path.endsWith(LOGIN_PATH) || path.endsWith(LOGOUT_PATH) || path.endsWith(LOADDB_PATH)) {
// if logging in, logging out, or loading the database, let the request flow
chain.doFilter(req, resp);
return;
}
Cookie cookies[] = request.getCookies();
Cookie sessionCookie = null;
if (cookies != null) {
for (Cookie c : cookies) {
if (c.getName().equals(LoginREST.SESSIONID_COOKIE_NAME)) {
sessionCookie = c;
}
if (sessionCookie!=null)
break;
}
String sessionId = "";
if (sessionCookie!=null) // We need both cookie to work
sessionId= sessionCookie.getValue().trim();
// did this check as the logout currently sets the cookie value to "" instead of aging it out
// see comment in LogingREST.java
if (sessionId.equals("")) {
response.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}
JSONObject jsonObject = authService.validateSession(sessionId);
if (jsonObject != null) {
String loginUser=(String) jsonObject.get("customerid");
request.setAttribute(LOGIN_USER, loginUser);
chain.doFilter(req, resp);
return;
} else {
response.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}
}
// if we got here, we didn't detect the session cookie, so we need to return 404
response.sendError(HttpServletResponse.SC_FORBIDDEN);
}
示例8: getRequestedPath
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
private String getRequestedPath(HttpServletRequest request) {
String path = request.getServletPath();
if (request.getPathInfo() != null) {
path = path + request.getPathInfo();
}
return path;
}
示例9: getServletPath
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
public String getServletPath(HttpServletRequest req)
{
if(overrideServletPath)
{
return servletPathOverride;
}
else
{
return req.getServletPath();
}
}
示例10: isIgnoredRequest
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
private boolean isIgnoredRequest(HttpServletRequest request) {
String path = request.getServletPath();
List<String> ignoredPatterns = applicationProperties.getTenantIgnoredPathList();
if (ignoredPatterns != null && path != null) {
for (String pattern : ignoredPatterns) {
if (matcher.match(pattern, path)) {
return true;
}
}
}
return false;
}
示例11: InvokerHttpRequest
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
/**
* Construct a new wrapped request around the specified servlet request.
*
* @param request The servlet request being wrapped
*/
public InvokerHttpRequest(HttpServletRequest request) {
super(request);
this.pathInfo = request.getPathInfo();
this.pathTranslated = request.getPathTranslated();
this.requestURI = request.getRequestURI();
this.servletPath = request.getServletPath();
}
示例12: getRequestPath
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
private String getRequestPath(HttpServletRequest request) {
String url = request.getServletPath();
String pathInfo = request.getPathInfo();
if (pathInfo != null) {
url += pathInfo;
}
return url;
}
示例13: doGet
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
/**
* Process a GET request for the specified resource.
*
* @param request
* The servlet request we are processing
* @param response
* The servlet response we are creating
*
* @exception IOException
* if an input/output error occurs
* @exception ServletException
* if a servlet-specified error occurs
*/
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
StringManager smClient = StringManager.getManager(Constants.Package, request.getLocales());
// Identify the request parameters that we need
String command = request.getPathInfo();
if (command == null)
command = request.getServletPath();
String name = request.getParameter("name");
// Prepare our output writer to generate the response message
response.setContentType("text/plain; charset=" + Constants.CHARSET);
PrintWriter writer = response.getWriter();
// Process the requested command
if (command == null) {
writer.println(sm.getString("hostManagerServlet.noCommand"));
} else if (command.equals("/add")) {
add(request, writer, name, false, smClient);
} else if (command.equals("/remove")) {
remove(writer, name, smClient);
} else if (command.equals("/list")) {
list(writer, smClient);
} else if (command.equals("/start")) {
start(writer, name, smClient);
} else if (command.equals("/stop")) {
stop(writer, name, smClient);
} else {
writer.println(sm.getString("hostManagerServlet.unknownCommand", command));
}
// Finish up the response
writer.flush();
writer.close();
}
示例14: getOriginatingServletPath
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
/**
* Return the servlet path for the given request, detecting an include request
* URL if called within a RequestDispatcher include.
* @param request current HTTP request
* @return the servlet path
*/
public String getOriginatingServletPath(HttpServletRequest request) {
String servletPath = (String) request.getAttribute(WebUtils.FORWARD_SERVLET_PATH_ATTRIBUTE);
if (servletPath == null) {
servletPath = request.getServletPath();
}
return servletPath;
}
示例15: doFilter
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
private void doFilter(RequestContext context) throws IOException, ServletException {
HttpServletRequest request = context.getRequest();
String path = request.getContextPath() + request.getServletPath();
if (request.getPathInfo() != null) {
path = path + request.getPathInfo();
}
logger.debug("Get the request path {}", path);
if (path.endsWith(LOGIN_PATH) || path.endsWith(LOGOUT_PATH) || path.endsWith(LOADDB_PATH) ||
path.contains(CONFIG_PATH) || path.contains(LOADER_PATH)) {
// if logging in, logging out, lookup configuration, or loading the database , let the request flow
return;
}
Cookie cookies[] = request.getCookies();
Cookie sessionCookie = null;
if (cookies != null) {
for (Cookie c : cookies) {
if (c.getName().equals(CustomerSession.SESSIONID_COOKIE_NAME)) {
sessionCookie = c;
}
if (sessionCookie!=null)
break;
}
String sessionId = "";
if (sessionCookie!=null) // We need both cookie to work
sessionId= sessionCookie.getValue().trim();
// did this check as the logout currently sets the cookie value to "" instead of aging it out
// see comment in LogingREST.java
if (sessionId.equals("")) {
logger.warn("Session id is empty");
setFailedRequest(HttpServletResponse.SC_FORBIDDEN);
return;
}
// Need the URLDecoder so that I can get @ not %40
CustomerSession cs = getCustomerSession(sessionId);
if (cs != null) {
context.addZuulRequestHeader(LOGIN_USER, cs.getCustomerid());
logger.info("Customer {} validated with session id {}", cs.getCustomerid(), sessionId);
return;
}
else {
logger.warn("No customer session found with session id {}", sessionId);
setFailedRequest(HttpServletResponse.SC_FORBIDDEN);
return;
}
}
logger.warn("No session cookie provided");
// if we got here, we didn't detect the session cookie, so we need to return 404
setFailedRequest(HttpServletResponse.SC_FORBIDDEN);
}