Reputation: 201
I have been stuck with this problem for two days now and I cant find a solution.
I have this project structure as above:
I want to forward a request from
Survey
(it is a Servlet) to survey.jsp
.
Now when I deploy this from IntelliJ
on localhost the forward is made with success. Now i take the .war
and use the Tomcat Apache
manager to deploy it to a dedicated Server.
When i call dedicatedserverip:8080
the index.jsp
loads properly as in localhost:8080
. But when it comes to forward there are two cases:
.war
file is different from survey.war
when the forward happens I get error 404 . (In this case I think that the request is forwarded to dedicatedserverip:8080
).war
file is survey.war
when forward happens it happens to load again index.jsp
page. (in this case I think the request is forwarded to dedicatedserverip:8080/survey
)Below is the code I use to forward the request:
req.getRequestDispatcher("/survey.jsp").forward(req, resp);
Now my question is: Is there something done wrong? Or is there something that I must understand that I haven't? How can I fix it and get the needed result as in localhost?
Upvotes: 0
Views: 518
Reputation: 201
Finally, I solved the problem. It had nothing to do with the forward, the problem was in the submit form action. Action was action="/survey"
. I replaced with ${pageContext.request.contextPath}/survey
. And it solved the problem. This explains why the index page was called when .war
name was survey.war
and error page when it was different.
Thank you for your support.
Upvotes: 0
Reputation: 3507
Have you tried forwarding relative instead of absolute?
req.getRequestDispatcher("survey.jsp").forward(req, resp);
Then additionally it should be no problem if you change the name of your war file and with it the ServletContext of the application any more.
Upvotes: 1