Skip to content Skip to sidebar Skip to footer

Servlet Not Forwarding - Servlet Exception

My servlet is not forwarding correctly. I keep getting forwarded to the Tomcat-8.5 404 or 500 error pages depending what I try. When I get the 500 error, it just says the servlet t

Solution 1:

Ok Let's analyze your code:

1.- dd (web.xml)

<servlet-class>SessionTracker</servlet-class>

Try not to use Default package, (Although there is no problem here)

<url-pattern>/donate/*</url-pattern>

Oh Boy, here is a problem, you're saying to the Container, HEY, If someone uses the url http://localhost:8080/mysite/donate/whateverIDon'tCare call the Servlet SessionTracker, so I can use this diferents paths and it will call the same Servlet

/mysite/donate/some
/mysite/donate/hereWeGo
/mysite/donate/lol

So that is not good, try to change it to

<url-pattern>/donate/SesionTrackerServlet</url-pattern>

2.- Look at your

<li><ahref="/donate/donate.jsp?name=donate"name="donate">Donate</a</li>

can you see the failure? yes as I said , when a user click here it will call your Servlet, so your servlet will call your method forwardRequest and What do you think will happen? yes it will foward to url = "/donate/donate.jsp"; but wait, did you see my point 1? your will call again the servlet and again the method and again and again and again and booooom....Estado HTTP 500 - Servlet execution threw an exception because you made a Loop.

BUT AS I SAID CHANGE THAT TO THIS:

Web.xml

<servlet><servlet-name>SessionTracker</servlet-name><servlet-class>SessionTracker</servlet-class></servlet><servlet-mapping><servlet-name>SessionTracker</servlet-name><url-pattern>/donate/SessionTrackerServlet</url-pattern></servlet-mapping>

Now enter this url (of course change your port if you need)

http://localhost:8080/Test/donate/SessionTrackerServlet?name=donate

And woooala =)

[![enter image description here][1]][1][![enter image description here][2]][2][![enter image description here][3]][3][![enter image description here][4]][4][1]: https://i.stack.imgur.com/9hhTO.png[2]: https://i.stack.imgur.com/Hqha7.png[3]: https://i.stack.imgur.com/uUvn4.png[4]: https://i.stack.imgur.com/Tge2x.png

Post a Comment for "Servlet Not Forwarding - Servlet Exception"