Unable to configure Intellij Ultimate Web App deployment correctly

Answered

I'm trying to build a simple web app based on JSP and Servlets in IntelliJ, using Tomcat 9. But I'm having trouble linking the servlet and jsp files from localhost:8080.

The issue is, in IntelliJ, the normal way is to deploy your  "artifact"  which then compiles into a war/war:exploded, which is then run on the server (tomcat).

So, the root URL becomes localhost:8080/app_war_exploded instead of just localhost:8080. In this scenario, when I try to redirect to another servlet or JSP from the code, like so -

  response.sendRedirect("/todo.do");

This makes a GET request to localhost:8080/todo.do, which consequently throws a 404 error.

Instead, if I go to the browser and manually enter localhost:8080/app_war_exploded/todo.doit works fine.

I posted a question on StackOverflow with more details, but no response there yet.

Would appreciate any help.

0
2 comments

You just change the context here:

Please note that the app written this way is not portable and flexible. You should not depend on the context used for deployment and this part is not IDE specific and needs to be fixed in your code.

1
Avatar
Permanently deleted user

Serge Baranov Thank you very much sir you saved my life! I spent the whole afternoon, changed lots of things to no avail.

0

Please sign in to leave a comment.