Andrei Botalov
Andrei Botalov

Reputation: 21096

Servlets: sendRedirect is redirecting to incorrect url?

I run my app from Eclipse's Servers view. Currently urls that are shown to the user look like:

http://localhost:8082/EclipseProjectName/path

I haven't specified this EclipseProjectName anywhere in my files but it's present there.

Currently when I invoke response.sendRedirect("/path"), then user is redirected not to http://localhost:8082/EclipseProjectName/path, but to http://localhost:8082/path

How do I solve that problem?

Upvotes: 1

Views: 2247

Answers (2)

Michael Akerman
Michael Akerman

Reputation: 329

Try without the slash:

response.sendRedirect("path");

Upvotes: 0

Andrei Botalov
Andrei Botalov

Reputation: 21096

You should redirect to response.sendRedirect(request.getContextPath() + "/path"); But I don't know whether it's a correct way to do it

Upvotes: 2

Related Questions