• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Unsuccessful redirecting of servlet based using string query parameters

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Situation: In the code below I'm attempting to learn how to use form parameters specifically redirecting Java servlets by propagating string query parameters.

Problem: I can't seem to figure out why I'm facing a problem with re-directing the user from the form i.e. index.html using the desired string query paramters to the correct page.

Below are the steps I took before posting this up:
I made sure the URL pattern for the @WebServlet annotation is correct i.e. in my case /CityManagerWebStarter/mainmenuresponder.do

I made sure my content-root when looking at the URL is correct i.e. /CityManagerWebStarter and I can confirm this as when I launchthe following URL http://localhost:8080/CityManagerWebStarter/ it displays the index.html page as expected.

Below is my servlet code and following that is my index.html code and ListCities.html is an example of a page I'm attempting to re-direct the user to:

servlet code:



index.html:


ListCities.html:


I forgot to add my descriptor file content.



Thanks for any suggestions/help.
 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does your code even get inside the servlet doPost?

The servlet url pattern should not need to include the context path (/CityManagerWebStarter), "/mainmenuresponder.do" will do

The action in the html form again doesn't need the context path. Just "mainmenuresponder.do" should be enough

For Java EE 6, the servlet and servlet-mapping tags are not needed in web.xml. If present, I think they will override the url pattern in the servlet class but not sure. Anyhow, both should be the same.
 
Sheriff
Posts: 67590
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

K. Tsang wrote:The action in the html form again doesn't need the context path. Just "mainmenuresponder.do" should be enough


I strongly disagree. Making the URL page-relative makes it fragile and likely to stop working at some point in the future when something gets moved around. All resource URLs in a Java web app should be server-relative, starting with the context path. This makes them bulletproof against structural changes.

Of course, the context path should not be hard-coded. See the JspFaq for information on obtaining it programmatically.
 
Stop it! You're embarassing me! And you are embarrassing this tiny ad!
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic