Author | Message |
---|---|
cseidel2
Posts: 4
|
Posted 19:44 Oct 25, 2015 |
Not sure if anyone else is having this problem, but the response.sendRedirect("X") command is suddenly not working in my Homework1 project. For example, I am trying to test my Login servlet's redirection to MyNotes with the following code: protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String email = request.getParameter("email"); String pass = request.getParameter("password"); if (email.equals("john@doe.com") && pass.equals("1!")) { response.sendRedirect("MyNotes"); } }
However, when I click the "Sign in" button after entering the correct credentials, it merely reloads the page. Is there some way to fix this? response.sendRedirect was working perfectly fine during my midterm assignment and when I was using it elsewhere. Last edited by cseidel2 at
19:46 Oct 25, 2015.
|
mnava18
Posts: 86
|
Posted 19:47 Oct 25, 2015 |
did u try response.sendRedirect("../Homework2/MyNotes"); |
dbravoru
Posts: 60
|
Posted 19:50 Oct 25, 2015 |
MyNotes would be in a different package than Sign In (called Login on the pdf) Sign In is under package Homework 1 MyNotes would be Homework 2 so the above solution should work |
cseidel2
Posts: 4
|
Posted 19:52 Oct 25, 2015 |
Just now tried the first reply's code (with Homework1 in the path). It's still not working. The URL is updated with the parameters I entered, but it does not redirect to MyNotes Last edited by cseidel2 at
19:54 Oct 25, 2015.
|
mnava18
Posts: 86
|
Posted 20:02 Oct 25, 2015 |
did you put the 2 periods before homework2 like i did in my previous post? that was my problem. i had the same problem with my servlet. I was missing those .. before homework2. and it should be homework2 , not homework1.You can also test it to make sure its working by putting it in the same package as ur homework1 and using the redirect the way you originaly had it and seeing if it works. if it works their then its gotta be that your missing the two ,, before homerwork2 Last edited by mnava18 at
20:04 Oct 25, 2015.
|
dhairyapop25
Posts: 1
|
Posted 20:06 Oct 25, 2015 |
Try Cleaning your project. First Stop the server(from server tab besides console , Right click on your Tomcat Server and then click on stop if its still running) and then Even Clean your Tomcat server From the same Sever Tab. Hope this might help you. Good luck. |
vluu2
Posts: 64
|
Posted 20:07 Oct 25, 2015 |
The correct way of writing it in this project should be: response.sendRedirect("http://cs3.calstatela.edu:8080/cs320stuXX/Homework2/MyNotes"); Don't forget the http part. |
cseidel2
Posts: 4
|
Posted 20:19 Oct 25, 2015 |
Just gave it a try after switching the packages, cleaning the server, and everything, and it's still not working for some reason. I even eliminated all validating conditions so that doPost contains only the redirect command, but it still only reloads the page with parameters appended to the url. I ran the MyNotes page and it seems to be working fine on its own, but Login just isn't redirecting there for some reason. |
vluu2
Posts: 64
|
Posted 20:27 Oct 25, 2015 |
Are you using the same one i told you to use? The one where it's http://cs3.calstatela.edu:8080/cs320stuXX/Homework2/MyNotes ? If you're using this and it's not running on your Eclipse well it's prob because you haven't uploaded your MyNotes to the CS3 Server yet.. |
GeorgeAria
Posts: 14
|
Posted 20:49 Oct 25, 2015 |
If you think its a problem with response.sendRedirect, you could try redirecting to http://www.google.com. If that works, then like vluu said, it is most likely because you haven't uploaded it to the CS3 server since it should work there as opposed to working on your localhost. |
Miro138
Posts: 22
|
Posted 21:40 Oct 25, 2015 |
Haven't seen this suggested yet but, have you tried something like: response.sendRedirect(request.getContextPath()+ "/Homework2/MyNotes"); Had a similar problem due to the URL mapping of MyNotes being "/Homework2/..." versus login's "/Homework1/.." Last edited by Miro138 at
21:40 Oct 25, 2015.
|
mbarra10
Posts: 4
|
Posted 21:44 Oct 25, 2015 |
if you say you can see your parameters attached to the the url then you probably have the method set to get instead of post( method="get") inside of your form tag |
cseidel2
Posts: 4
|
Posted 22:24 Oct 25, 2015 |
response.sendRedirect() is now only working if I put it in doGet. In fact, it seems that any commands I enter into doPost are not executed, so it's not working altogether. Eclipse tells me my doPost method is overwriting the original, so I'm quite confused as to why this is.... Any thoughts? Last edited by cseidel2 at
22:24 Oct 25, 2015.
|
kiinokiino
Posts: 1
|
Posted 23:35 Oct 25, 2015 |
I have been getting these problems to in the the doPost method. It has seemed to start working for me just a minute ago, very odd. |