Java Code Examples for javax.servlet.http.HttpServletRequest.getRequestURL()

The following are Jave code examples for showing how to use getRequestURL() of the javax.servlet.http.HttpServletRequest class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: springMvc4.x-project   File: DemoAnnoController.java   View Source Code Vote up 6 votes
@RequestMapping(value = "/obj", produces = "application/json;charset=UTF-8")//⑦
@ResponseBody // ⑧
public String passObj(DemoObj obj, HttpServletRequest request) {

     return "url:" + request.getRequestURL() 
                + " can access, obj id: " + obj.getId()+" obj name:" + obj.getName();

}
 
Example 2
Project: oscm   File: PSPMockRegistrationEntry.java   View Source Code Vote up 6 votes
protected void doPost(HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException {
    PrintWriter writer = response.getWriter();
    Map<?, ?> parameterMap = request.getParameterMap();

    // store the parameters
    String sessionId = request.getSession().getId();
    ParameterStorage.addSessionParams(sessionId, parameterMap);

    ParameterHandler.addParametersToWriterInput(writer, parameterMap);
    StringBuffer requestURL = request.getRequestURL();
    int pos = requestURL.lastIndexOf("/");
    String redirectURL = requestURL.substring(0, pos + 1)
            + "PSPMockService?sessionId=" + sessionId;
    redirectURL = URLEncoder.encode(redirectURL, "UTF-8");
    writer.printf("%s=%s", "FRONTEND.REDIRECT_URL", redirectURL);

}
 
Example 3
Project: lambo   File: RequestParameterUtil.java   View Source Code Vote up 6 votes
/**
 * 移除url中的code、username参数
 * @param request
 * @return
 */
public static String getParameterWithOutCode(HttpServletRequest request) {
    StringBuffer backUrl = request.getRequestURL();
    String params = "";
    Map<String, String[]> parameterMap = request.getParameterMap();
    for (Map.Entry<String, String[]> entry : parameterMap.entrySet()) {
        if (!entry.getKey().equals("upms_code") && !entry.getKey().equals("upms_username")) {
            if (params.equals("")) {
                params = entry.getKey() + "=" + entry.getValue()[0];
            } else {
                params += "&" + entry.getKey() + "=" + entry.getValue()[0];
            }
        }
    }
    if (!StringUtils.isBlank(params)) {
        backUrl = backUrl.append("?").append(params);
    }
    return backUrl.toString();
}
 
Example 4
Project: lambo   File: UpmsAuthenticationFilter.java   View Source Code Vote up 6 votes
@Override
protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws Exception {
    StringBuffer sso_server_url = new StringBuffer(PropertiesFileUtil.getInstance("lambo-upms-client").get("lambo.upms.sso.server.url"));
    // server需要登录
    String upmsType = PropertiesFileUtil.getInstance("lambo-upms-client").get("lambo.upms.type");
    if ("server".equals(upmsType)) {
        WebUtils.toHttp(response).sendRedirect(sso_server_url.append("/sso/login").toString());
        return false;
    }
    sso_server_url.append("/sso/index").append("?").append("appid").append("=").append(PropertiesFileUtil.getInstance("lambo-upms-client").get("lambo.upms.appID"));
    // 回跳地址
    HttpServletRequest httpServletRequest = WebUtils.toHttp(request);
    StringBuffer backurl = httpServletRequest.getRequestURL();
    String queryString = httpServletRequest.getQueryString();
    if (StringUtils.isNotBlank(queryString)) {
        backurl.append("?").append(queryString);
    }
    sso_server_url.append("&").append("backurl").append("=").append(URLEncoder.encode(backurl.toString(), "utf-8"));
    WebUtils.toHttp(response).sendRedirect(sso_server_url.toString());
    return false;
}
 
Example 5
Project: bnade-web-ssh   File: ExceptionHandle.java   View Source Code Vote up 5 votes
@ExceptionHandler(UnknownResourceException.class)
@ResponseStatus(value = HttpStatus.NOT_FOUND)
@ResponseBody
public Result handle404Error(HttpServletRequest req) {
    String url = req.getMethod() + " " + req.getRequestURL() + "?" + req.getQueryString();
    logger.debug("找不到url资源 {}", url);
    ResultEnum notFound = ResultEnum.NOT_FOUND;
    return ResultUtils.error(notFound.getCode(), notFound.getMessage(), url);
}
 
Example 6
Project: EasyPackage   File: InvocationUtil.java   View Source Code Vote up 5 votes
public static String getInfo(@NonNull Invocation inv) {
    HttpServletRequest request = inv.getRequest();
    return "requestURI:" + request.getRequestURI()
            + ", resourceId:" + inv.getResourceId()
            + ", queryString:" + request.getQueryString()
            + ", requestURL:" + request.getRequestURL()
            + ", parameterMap:" + request.getParameterMap()
            + ", requestPath:" + inv.getRequestPath();
}
 
Example 7
Project: bnade-web-ssh   File: ExceptionHandle.java   View Source Code Vote up 5 votes
@ExceptionHandler(value = {IllegalArgumentException.class,
        BindException.class, // controller中参数绑定bean时异常,如数据类型不匹配等
        MissingServletRequestParameterException.class,
        MethodArgumentTypeMismatchException.class,
        HttpRequestMethodNotSupportedException.class})
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
@ResponseBody
public Result handle400Error(HttpServletRequest req, Exception e) {
    String url = req.getMethod() + " " + req.getRequestURL() + "?" + req.getQueryString();
    logger.debug("不合法的url请求: {}", url);
    ResultEnum badRequest = ResultEnum.BAD_REQUEST;
    return ResultUtils.error(badRequest.getCode(), badRequest.getMessage(), url);
}
 
Example 8
Project: springMvc4.x-project   File: DemoAnnoController.java   View Source Code Vote up 5 votes
@RequestMapping(value = "/obj", produces = "application/json;charset=UTF-8")//⑦
@ResponseBody // ⑧
public String passObj(DemoObj obj, HttpServletRequest request) {

     return "url:" + request.getRequestURL() 
                + " can access, obj id: " + obj.getId()+" obj name:" + obj.getName();

}
 
Example 9
Project: prom-bitbucket-exporter   File: AdminMetricsSecurityTokenServlet.java   View Source Code Vote up 5 votes
private URI getUri(HttpServletRequest request) {
    StringBuffer builder = request.getRequestURL();
    if (request.getQueryString() != null) {
        builder.append("?").append(request.getQueryString());
    }
    return URI.create(builder.toString());
}
 
Example 10
Project: lams   File: OAuthServlet.java   View Source Code Vote up 5 votes
/** Reconstruct the requested URL, complete with query string (if any). */
public static String getRequestURL(HttpServletRequest request) {
    StringBuffer url = request.getRequestURL();
    String queryString = request.getQueryString();
    if (queryString != null) {
        url.append("?").append(queryString);
    }
    return url.toString();
}
 
Example 11
Project: springMvc4.x-project   File: DemoAnnoController.java   View Source Code Vote up 4 votes
@RequestMapping(value = { "/name1", "/name2" }, produces = "text/plain;charset=UTF-8")//⑨
public @ResponseBody String remove(HttpServletRequest request) {

    return "url:" + request.getRequestURL() + " can access";
}
 
Example 12
Project: springMvc4.x-project   File: DemoAnnoController.java   View Source Code Vote up 4 votes
@RequestMapping(produces = "text/plain;charset=UTF-8")  // ③
public @ResponseBody String index(HttpServletRequest request) { // ④
    return "url:" + request.getRequestURL() + " can access";
}
 
Example 13
Project: java_springboot   File: DemoAnnoController.java   View Source Code Vote up 4 votes
@RequestMapping(value = {"/name1","/name2"},produces =
        "text/plain;charset=UTF-8")
public @ResponseBody String remove(HttpServletRequest request){
    return "url:"+ request.getRequestURL() + " can access";
}
 
Example 14
Project: springMvc4.x-project   File: DemoAnnoController.java   View Source Code Vote up 4 votes
@RequestMapping(value = { "/name1", "/name2" }, produces = "text/plain;charset=UTF-8")//⑨
public @ResponseBody String remove(HttpServletRequest request) {

    return "url:" + request.getRequestURL() + " can access";
}
 
Example 15
Project: springMvc4.x-project   File: DemoAnnoController.java   View Source Code Vote up 4 votes
@RequestMapping(value = { "/name1", "/name2" }, produces = "text/plain;charset=UTF-8")//⑨
public @ResponseBody String remove(HttpServletRequest request) {

    return "url:" + request.getRequestURL() + " can access";
}
 
Example 16
Project: springMvc4.x-project   File: DemoAnnoController.java   View Source Code Vote up 4 votes
@RequestMapping(produces = "text/plain;charset=UTF-8")  // ③
public @ResponseBody String index(HttpServletRequest request) { // ④
    return "url:" + request.getRequestURL() + " can access";
}
 
Example 17
Project: springMvc4.x-project   File: DemoAnnoController.java   View Source Code Vote up 4 votes
@RequestMapping(value = "/pathvar/{str}", produces = "text/plain;charset=UTF-8")// ⑤
public @ResponseBody String demoPathVar(@PathVariable String str, //③
        HttpServletRequest request) {
    return "url:" + request.getRequestURL() + " can access,str: " + str;
}
 
Example 18
Project: springMvc4.x-project   File: DemoAnnoController.java   View Source Code Vote up 4 votes
@RequestMapping(value = "/pathvar/{str}", produces = "text/plain;charset=UTF-8")// ⑤
public @ResponseBody String demoPathVar(@PathVariable String str, //③
        HttpServletRequest request) {
    return "url:" + request.getRequestURL() + " can access,str: " + str;
}
 
Example 19
Project: springMvc4.x-project   File: DemoAnnoController.java   View Source Code Vote up 4 votes
@RequestMapping(value = { "/name1", "/name2" }, produces = "text/plain;charset=UTF-8")//⑨
public @ResponseBody String remove(HttpServletRequest request) {

    return "url:" + request.getRequestURL() + " can access";
}
 
Example 20
Project: springMvc4.x-project   File: DemoAnnoController.java   View Source Code Vote up 4 votes
@RequestMapping(produces = "text/plain;charset=UTF-8")  // ③
public @ResponseBody String index(HttpServletRequest request) { // ④
    return "url:" + request.getRequestURL() + " can access";
}