How to inspect JSP request URL for String

Posted by IAmYourFaja on Stack Overflow See other posts from Stack Overflow or by IAmYourFaja
Published on 2014-06-02T17:53:38Z Indexed on 2014/06/02 21:27 UTC
Read the original article Hit count: 140

Filed under:
|

I have the following processor.jsp file:

<%
    response.sendRedirect("http://buzz.example.com");
%>

I want to change it so that it inspects the HTTP request URL for the presence of the word "fizz" and, if it exists, redirect the user to http://fizz.example.org instead.

So something like:

<%
    String reqUrl = request.getURL().toLowerCase();
    String token = null;
    if(reqUrl.contains("fizz")) {
        token = "fizz";
    } else {
        token = "buzz";
    }

    String respUrl = "http://%%%TOKEN%%%.example.com".replace("%%%TOKEN%%%", token);
    response.sendRedirect(respUrl);
%>

However this doesn't work. Any ideas on what I should be using instead of request, or if I'm doing anything else wrong?

© Stack Overflow or respective owner

Related posts about java

Related posts about jsp