• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unable to get the desired result as Hello UserName

 
Abhimanyu Jain
Ranch Hand
Posts: 151
1
Eclipse IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Following is the code











I am able to compile the code but not able to get the desired result. It should give me the "HELLO <USERNAME>" but it is not.

Kindly help me with this. Thanks in advance
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65342
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is it giving you?
 
Abhimanyu Jain
Ranch Hand
Posts: 151
1
Eclipse IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It gives an error 404 related to checkcookie.do.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65342
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's important information that you should include at the beginning.

Have you worked through the suggestions in the ServletsFaq for this issue?
 
Abhimanyu Jain
Ranch Hand
Posts: 151
1
Eclipse IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did not include it as it runs first but at the end instead of giving the result gives the error.

Do I still need to check the FAQs?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65342
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, there is an entry with a checklist to go through when getting 404 errors.

Assume that you always should check the ServletsFaq before posting to check if your question has already been answered.
 
Abhimanyu Jain
Ranch Hand
Posts: 151
1
Eclipse IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I went through the FAQs but it did not resolve the issue I am facing. I am sorry.

I could not find anything in the logs.

Could you please help?


 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65342
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, what have you changed as a result of going through the list? I see at least two errors that list should have helped you find.
 
Abhimanyu Jain
Ranch Hand
Posts: 151
1
Eclipse IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I put the servlet classes in package after going through the list.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65342
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Two things:
  • This is a page-relative url; bad news. Be sure to use server-relative urls that start with the context path. See the JspFaq for more info.
  • Where is checkcookie.do mapped?
  •  
    Abhimanyu Jain
    Ranch Hand
    Posts: 151
    1
    Eclipse IDE Java MySQL Database
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I will go through JSPFAQs but how do I map checkcookie.do.

    I was thinking about it but could find a clue how to map it.
     
    Bear Bibeault
    Author and ninkuma
    Marshal
    Pie
    Posts: 65342
    97
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Do you understand the contents of the web.xml file?
     
    Abhimanyu Jain
    Ranch Hand
    Posts: 151
    1
    Eclipse IDE Java MySQL Database
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Oh! I got it. Thanks!
     
    Abhimanyu Jain
    Ranch Hand
    Posts: 151
    1
    Eclipse IDE Java MySQL Database
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I configured web.xml as follows but it did not work. Following is the file



    How do I configure "checkcookie.do" in DD? This is not the right way for sure otherwise it would have worked.
     
    Bear Bibeault
    Author and ninkuma
    Marshal
    Pie
    Posts: 65342
    97
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I thought you said you put the servlets into a package?
     
    Abhimanyu Jain
    Ranch Hand
    Posts: 151
    1
    Eclipse IDE Java MySQL Database
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I put it in package on Eclipse IDE. But first I am trying to sort it out manually where the servlets are not in package.
     
    Bear Bibeault
    Author and ninkuma
    Marshal
    Pie
    Posts: 65342
    97
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Servlets must be in a package. And that must be reflected in your web.xml. That's one of the items on the list.
     
    Abhimanyu Jain
    Ranch Hand
    Posts: 151
    1
    Eclipse IDE Java MySQL Database
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    It worked!!

    Following is the code from the Eclipse IDE for web.xml



    Thanks again!!
     
    Bear Bibeault
    Author and ninkuma
    Marshal
    Pie
    Posts: 65342
    97
    IntelliJ IDE Java jQuery Mac Mac OS X
     
    Abhimanyu Jain
    Ranch Hand
    Posts: 151
    1
    Eclipse IDE Java MySQL Database
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Could you please help me with encodeURL as well, following is the code but it is not working as it should



    It shows a blank page after hitting the submit button instead of adding a jsessionid to the URL and showing the result.
     
    Bear Bibeault
    Author and ninkuma
    Marshal
    Pie
    Posts: 65342
    97
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    What is the path to cookieresult.jsp?
     
    Abhimanyu Jain
    Ranch Hand
    Posts: 151
    1
    Eclipse IDE Java MySQL Database
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    cookieresult.jsp is at the root of the application with login.html
     
    Bear Bibeault
    Author and ninkuma
    Marshal
    Pie
    Posts: 65342
    97
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    How is the method to know that when you have provided no path? Hint: try a leading /.
     
    Abhimanyu Jain
    Ranch Hand
    Posts: 151
    1
    Eclipse IDE Java MySQL Database
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I already tried it but it did not work. I disabled cookies in all the browsers I have (Chrome, IE and Firefox) but same result all the time.

    So what's the next step now?

    Thanks in advance

     
    Bear Bibeault
    Author and ninkuma
    Marshal
    Pie
    Posts: 65342
    97
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I just noticed this: why are you calling encodeURL for a forward? Don't do that.
     
    Abhimanyu Jain
    Ranch Hand
    Posts: 151
    1
    Eclipse IDE Java MySQL Database
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    OK. Then how do I call encodeURL? I replaced RequestDispatcher with encodeURL but it did not work.
     
    Bear Bibeault
    Author and ninkuma
    Marshal
    Pie
    Posts: 65342
    97
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I already told you: don't call encodeURL. It's not for use with forwards.
     
    Abhimanyu Jain
    Ranch Hand
    Posts: 151
    1
    Eclipse IDE Java MySQL Database
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    OK. But then how do I see JSESSIONID appended to the URL. I wish to use the method "encodeURL()" so I could understand how it works and when to use it.

    Please help!!
     
    Bear Bibeault
    Author and ninkuma
    Marshal
    Pie
    Posts: 65342
    97
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    You only use it with redirects; not with forwards.
     
    Abhimanyu Jain
    Ranch Hand
    Posts: 151
    1
    Eclipse IDE Java MySQL Database
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I tried but it did not work. I have no clue now. But I want to fix it somehow.
     
    Bear Bibeault
    Author and ninkuma
    Marshal
    Pie
    Posts: 65342
    97
    IntelliJ IDE Java jQuery Mac Mac OS X
     
    Abhimanyu Jain
    Ranch Hand
    Posts: 151
    1
    Eclipse IDE Java MySQL Database
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I didn't get you I am sorry. Should I leave it now?
     
    Bear Bibeault
    Author and ninkuma
    Marshal
    Pie
    Posts: 65342
    97
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Read the link I posted. It's a link to a FAQ article.
     
    Abhimanyu Jain
    Ranch Hand
    Posts: 151
    1
    Eclipse IDE Java MySQL Database
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I am really sorry.

    Following is the code I changed it to:-

     
    Bear Bibeault
    Author and ninkuma
    Marshal
    Pie
    Posts: 65342
    97
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    You either need to do a forward or a redirect. Right now, you're not doing either so of course nothing will happen.
     
    Abhimanyu Jain
    Ranch Hand
    Posts: 151
    1
    Eclipse IDE Java MySQL Database
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I changed the code but still it shows a blank page



    I thought I could use "encodeURL()" after disabling the cookies on the browser as "encodeURL()" adds "jsessionid" at the end of the URL if the cookies are disabled.
     
    Paul Clapham
    Sheriff
    Posts: 21583
    33
    Eclipse IDE Firefox Browser MySQL Database
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Bear Bibeault wrote:You either need to do a forward or a redirect. Right now, you're not doing either so of course nothing will happen.


    This statement is still true about the code you just posted.
     
    Abhimanyu Jain
    Ranch Hand
    Posts: 151
    1
    Eclipse IDE Java MySQL Database
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    But I am using redirect now as told
     
    Abhimanyu Jain
    Ranch Hand
    Posts: 151
    1
    Eclipse IDE Java MySQL Database
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Now I changed it to the following but still nothing

     
    Bear Bibeault
    Author and ninkuma
    Marshal
    Pie
    Posts: 65342
    97
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Your redirect URL is page-relative. Bad idea. For a redirect you need to use a server-relative URL if the path is on the same server, or an absolute path if on a different server.

    Look at it from the point of view of the container: with the scant information you've given it -- just a page name -- how is it supped to find it? It's like saying "Where does Ralph live?" with the answer "In a blue house". Good luck finding Ralph.

     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic