• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

url is changing by requestdispatcher

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i am designing a website for a shopping mall. here i have some items on a page. when i click on 1 item, its detailed information must be shown to the user. i created a servlet for that. when the user click on the item , onitemclick is called which get the data from database and the forward it to a jsp items.jsp.. so now i think when the servlet forward, the url must be http://localhost:8080/project2/pages/items.jsp but i am not getting this url in browser. i got the url http://localhost:8080/project2/itemclick?x=63&y=96&text1=l1 .... please tell me why i am getting this url.


items.jsp

 
Sachin Kadian
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
onitemclick.java



the problem due to this url change is that i am not getting the image on jsp.. when instead of this url i enter manually the url http://localhost:8080/project2/pages/items.jsp the image is displayed. please help me. its very urgent.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sachin Kadian wrote:its very urgent.


Please EaseUp; there is no such thing as "urgent" around here. And also, PatienceIsAVirtue.
 
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As what I can see from your code,

1. You have a HTML form inside a jsp page whose action is http://localhost:8080/project2/addcart.
2. The URL pattern "/addcart" is mapped to a Servlet
3. The Servlet does it processing in its doGet method as you invoke it via HTTP get method in the HTML form.
4. It executes a SQL query
5. It checks for the result set with an if-else for any valid rows being returned
6. If there are any valid rows [while(rs.next()..] it forwards the control to /pages/items.jsp via RequestDispatcher.
7. If there are NO valid rows (else), it prints out an error message.

Now, you have to confirm whether you get the #7 above is executed or not. Are there any valid rows being returned? Execute your SQL query directly in the SQL Client and try to see.
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sachin Kadian wrote: i got the url http://localhost:8080/project2/itemclick?x=63&y=96&text1=l1 .... please tell me why i am getting this url.


browser and server are there in same machine? is it web application?
 
Raghavan Muthu
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Seetharaman Venkatasamy wrote:

Sachin Kadian wrote: i got the url http://localhost:8080/project2/itemclick?x=63&y=96&text1=l1 .... please tell me why i am getting this url.


browser and server are there in same machine? is it web application?



I see it to be 'Yes' as both the URLs are hard coded with localhost. I thought of suggesting it later once the issue is resolved.

It is definitely a web application because of having JSP and Servlet.
 
Sheriff
Posts: 67746
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
The URL for the JSP will never be shown as the result of a forward, and it shouldn't! If it did, a refresh on the browser would cause the JSP to try and display again without running its controller.

The flow of control in your web app is very poor and is not following proper patterns. Please read this article paying special attention to the PRG pattern.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmm Agree most of the stand alone applications are build in RCP, swing or awt. but you can also use servlet/jsp
 
Raghavan Muthu
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:The URL for the JSP will never be shown as the result of a forward, and it shouldn't! If it did, a refresh on the browser would cause the JSP to try and display again without running its controller.



Excellent point Bear! Expert advice!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic