• 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

Help with JSP form

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys, I am trying to create a form that will be queried in Java. What I need to achieve is that when you select the drop down below and click the submit button the link should be http://localhost:8080/mm00422_COM1028_part1/UserController?action=searchAlbum&searchItem=itemSearched

The itemSearched will be the actual item being searched. Below is my current form, I have been playing around with it but I cannot get it to work

 
Ranch Hand
Posts: 355
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
:) I think you need to get your html code correct first. Then you will see that the rest will be easy.
 
misheck Mberi
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I cannot really find anything wrong with my code? I know I have been playing around with it for the whole day so I am not sure if I have messed the form up.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, look at this tag:



That says that you want the value of the URL's "action" parameter to be "searchAlbum". But then you have a <select> element whose name is "action". This suggests that you want the user to control the value of the URL's "action" parameter. So you're going to have to decide which of those two things is your actual requirement. Once you have decided that, remove the un-required code. There are other unexplained things, too... for example why do you have "&searchItem" at the end of the form's action if you're going to have an <input> element named "searchItem"?
 
Paul Ngom
Ranch Hand
Posts: 355
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


<form method="GET" action='UserController?action=searchAlbum&searchItem' id="searchbox" >


Try this in place

<form method="GET" action='UserController' name="searchbox" >

You don't need to worry about the parameters, they will be appended automatically when the form is submitted.

And i do not understand what you are trying to do here as follows


<option value="searchArtist searchItem = <%= request.getParameter("searchItem") %>">Artist</option>



here also it seems you had forgotten to name your input field


<input ="searchItem" type="text" value="Type search items here">





 
misheck Mberi
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for the replies. I had too many problems until I added the action on the select tag, thats how I managed to get my code to perform the search action. I have now changed my code to this

My problem now is how do I add the eg action=searchAlbum&searchItem=Bad; so that I just take the value entered in the search item and use it for searching for Artist, Song, Year Released and the Album.
 
Paul Ngom
Ranch Hand
Posts: 355
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I will advice you to replace the 'id=...' in form and input fields by 'name=...'

As your code stands now, it will not call another page. Since you said it is performing as you want it, all is well.
 
misheck Mberi
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Paul Ngom but its not quite performing what I want it to do. I am still having problems adding "&searchItem=the item being searched", I am able to get the right action but the java controller on the other end will still need to retrieve the value of the search item to run a query on the database.
 
Paul Ngom
Ranch Hand
Posts: 355
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


I am still having problems adding "&searchItem=the item being searched", I am able to get the right action but the java controller on the other end will still need to retrieve the value of the search item to run a query on the database.



I am unable to understand what you mean. Where do you want to add "&searchItem=the item being searched"? You just need to retrieve the value of searchItem and do your search based on the value of action.
 
misheck Mberi
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Paul, it looks like my error has been fixed when I was doing some of the changes you mentioned. It is now working like I am expecting it to.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic