tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <>
Subject Re: From HTTP to HTTPS request.getHeader("referer")
Date Mon, 03 Nov 2014 15:34:24 GMT
Hash: SHA256


On 11/2/14 10:07 AM, Léa Massiot wrote:
> Hello Mark, Chris and Terence. Thank you for your answers. After
> reading them and observing a few things I realized that my problem
> is not exactly the one I described at first.
> Christopher Schultz-2 wrote
>> The Referer is going to be the URL that was showing in the web
>> browser when the user clicked on the Submit button.
> This is right. I hadn't noticed it but the URL which is showing is
> NOT https://host/webapp/example1.jsp. Instead, it is
> https://host/webapp/do_example. So, what I was describing as
> abnormal in my first post is actually normal.


> So the problem is coming from elsewhere...
> Before I tried to make the webapp work with HTTPS, I was always
> using calls like these: 
> ----------------------------------------------------------------------

When sending redirects, you probably always want to:

1. Run the URL through response.encodeRedirectURL
2. Use a URL that starts with "/", which is easiest by doing this:

  String url = response.encodeRedirectURL(request.getContextPath()
                                          + "/example1.jsp"));


> ----------------------------------------------------------------------
>  Last week, I replaced all these calls with these new ones: 
> ----------------------------------------------------------------------
requestDispatcher =
> getServletContext().getRequestDispatcher("/example1.jsp"); 
> requestDispatcher.forward(request, response); 
> ----------------------------------------------------------------------
(with the appropriate JSP of course).
> I made that change because "sendRedirect()" didn't "work" with

Redirects definitely work with HTTPS. You must be doing something
wrong. Perhaps a configuration mistake with a port number or something
like that.

> I didn't mention this before because I thought it was solving this
> other problem. Instead, it provokes new ones.


> What I actually would like is the webapp to behave like before:
> showing JSP page names in the URLs bar instead of "URL patterns": 
> in a given servlet, I generally have several "forward()" calls and
> hence several different ".jsp" pages to forward to depending on
> what happens inside the servlet. Having all of them replaced by
> something like "do_example" is kind of not what I had planned. It's
> definitely very problematic.

So use redirects. They should work and you should figure out why they
aren't working. Put your code back the way you had it, take more data,
and post a new question if you need help.

> So, hum, as I didn't asked it at the time: why can't I go on using 
> "sendRedirect()" along with HTTPS? If I have to use "forward()", is
> there any way I could make it behave the way I described above?

When you use a "forward", you will always end up with the URL the
client first used as what the client "sees". If you want to accept
data (e.g. POST) *and* prepare some data for the next screen to be
seen, consider a POST-then-redirect scheme:

1. Client POSTs to some URL e.g. /do_example
2. /do_example servlet runs and handles the POST data, then
redirect()s to /prepare_view
3. /prepare_view servlet runs and gathers whatever data is appropriate
for the next display screen and forward()s to /example1.jsp

After all that, the user is looking at the URL /prepare_view instead
of /do_example. That way, your referrer for the next POST will be
/prepare_view instead of /do_example.

> Is there another method I could use that would suit my needs?

Your only tools to transfer control (other than direct function calls)
are forward, redirect, and include.

> P.S. For the problem I was posting at first, as I don't really need
> to rely on the "referer" request header, I can instead, set a
> session attribute in each JSP. In "example1.jsp" for instance: 
> --------------------------------------------------------------------
<c:set var="sessAtt"
> value="example1.jsp" scope="session"></c:set> 
> --------------------------------------------------------------------
When in the "doPost()" method of the servlet, I'll know which JSP form what
> submitted...

What if the user hits the BACK button and looks at a previous page,
then re-submits that old page? Your server thinks that the source page
was "example1.jsp" but the client actually posted example0.jsp or
something else...

Web application workflow management is non-trivial.

- -chris
Version: GnuPG v1
Comment: GPGTools -


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message