• 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

Using servlets

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My error from my previous post in JSP's now leads onto servlets. I was trying to figure out why i was being given the message that my data has been saved to my database, even though it hadnt. So i done some messing about with the code and found out somthing i just wish to confirm.
I have a register and login servlet, which obviously registers and logs in a user. If the user successfully logs in, then the servlet points them to here


Now in this jsp, the user has four buttons to choose, each one taking them to a new jsp. I did not however provide a servlet to this jsp in order to point the user to the new jsp. I thought i could get away with doing this


This brings up the jsp no problems, but it seems to make it no longer part of my hierachy. I am pretty sure this is my problem as i removed all the register and logn servlet and code, and i pointed my browser straight to the jsp where the user can enter a competitor (The one where no data was previously going to database). But this time it works and data is being saved. Does this make sense? So when i create a project, all linking should be done through servlets? Or can anyone think of another reason why this might of been happening?
cheers
 
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
Putting an onclick on a submit button is a recipe for disaster. What's your real intention?
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I didn't completely understand the question but if you want four submit buttons to point to four different JSPs, then you can use separate forms for them like this

 
Nick Price
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Its difficult to explain my intention, but basically i want that jsp to load up different jsp's when a button is click. The problem i have at the moment, using the onClick command, everything loads up ok but the data never goes to the database. Its like i need a servlet to handle the actions. So if i use


Possibly removing the first line, i could then prov ide a servlet like


This way i am handling the forwarding through a servlet, and involving my Bean with it. Would this be a better approach?
 
Bear Bibeault
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
If you are not submitting a form, don't use a submit button. If you are submitting a form, use the form action to specify the target, not an onclick.

In any case, forms should always be submitted to servlets, not JSPs.
 
Nick Price
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have tried a lot of different things, but now i am a bit stuck as to what to do. SO my user logs in, and my UserServlet handles this


So if the result is one, it brings up my CreateAtlDatabase.jsp, which is the first display page when they log in. This page has three buttons. One of them is too add a comeptitor. So i have a servlet which handles adding a competitor, which request the competitors data from the addCompetitor.jsp and sends it off to the database.
This is my problem. If i use onClick in my CreateAthDatabase.jsp, all the pages work, and everything does what it is suppossed to do, Even getting a success message back saying competitor has been entered, but nothing gets saved into the database.
If i point my browser straight to AddCompetitor.jsp, rather than the starting point off my application, everything works fine as before but the data actually gets saved to the database this time(this would tend to tell me that the problem lies in CreateAthDatabase).
If i create a new servlet for CreateAthDatabase, when i click on the Add competitor link, which should take me to the AddCompetitor.jsp, i get back the error
The requested resource (/cmt3082/servlet/servlet/DatabaseServlet) is not available.
Which looks like its searching through two Servlets. SO this is where i am confused. What can i do with this CreateAthDatabase.jsp so that it forwards to the correct page (and allows the data to be saved)
 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nick Price wrote:The requested resource (/cmt3082/servlet/servlet/DatabaseServlet) is not available.

The relative URL which you specified was wrong. This may occur when you're currently in for example "/cmt3082/servlet/SomeServlet" and dispatched the request to "servlet/DatabaseServlet" instead of "/servlet/DatabaseServlet" or "DatabaseServlet". The context root of the requestdispatcher is "/cmt3082". Also see the API docs: http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletRequest.html#getRequestDispatcher(java.lang.String)
 
I don't even know how to spell CIA. But this tiny ad does:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic