• Post Reply Bookmark Topic Watch Topic
  • New Topic

ComboBox in jsp

 
Nick Price
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have been working through some of the previous errors i had, and now i want to try and validate that everything is working on the jsp side. I have create a combobox within a form like so


Now when the user selects a value from the above combo box, does it get saved into Events? Because my next step in my PrintResultsServlet, i am doing this


And i just wanted to check that this would work, because i am not getting the desired output yet, so i want to rule this out if i can.
thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65524
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's important to use correct terminology. HTML has no "combobox". Please read this for more information.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65524
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, the request parameter will reflect the user's selection.

And, why are you needlessly casting the result of the getParameter() method?
 
Nick Price
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, not quite sure as to what you mean by casting the result. Could you elaborate please?
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Expect of the unnecessary cast to String, I don't see a problem in the logic.

Edit: Sorry, Bear already pointed that out. Didn't see his reply before I posted my reply.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nick Price wrote:Sorry, not quite sure as to what you mean by casting the result. Could you elaborate please?

Read the API docs what HttpServletRequest#getParameter() actually returns.
http://java.sun.com/javaee/5/docs/api/javax/servlet/http/HttpServletRequest.html
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65524
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This line is needlessly complicated:

 
Nick Price
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, get you, so here is my major problem. So my selecting of events is in a form which is linked to my PrintResults servlet. In my servlet, i do thi


Now that should (or so i think) get the event, send it of to my database through a method, get returned a list and then forward this list back to my PrintResults.jsp. I know i have a successful list getting to my servlet, because at the bottom, i put a main method to test


And this returns me back the three fastest competitors for the 100M Run.
So now back to the jsp. I try to get the request and display it in a table. SO this is what i have done (problably tottally wrong but i have tried so many things)


As far as what happens, i am being returned an empty white page. Can you see where i might be going wrong?
thanks
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

As said, the cast is unnecessary.


Didn't you probably mean printCompetitors(event) instead? You're now passing the literal String instead of the variable you got.

Completely unnecessary. You should also not be writing scriptlets. Everytime you think you need scriptlets, there's a flaw in your design. Think twice about it then.
 
Nick Price
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, meant a hardcoded event, i was previously trying to pass it a String incase my "combo box" was not working. so i have forwarder the list to my jsp. If i dont need a scriplet, how would i display the list in my jsp?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65524
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What exactly is it that you think that scriptlet is doing for you?

Not only are scriptlets to be avoided like the plague, but this one is completely superfluous.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nick Price wrote:If i dont need a scriplet, how would i display the list in my jsp?


In ELroughly translates towhich scans for the attribute value associated with the given key in all scopes (page, request, session and application) and thus on its turn roughly translates to the following when you have placed it in the request scope using HttpServletRequest#setAttribute()With other words, your scriptlet is completely unnecessary.
 
Nick Price
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thats what i am trying to understand better so i can get rid of the scriplet. I thought that scriplet was getting the forwarded list i forward in my servlet. What i am trying to find out is how i can disply my list in my jsp. I have forwarded the list from my servlet to my jsp, so how do i retrieve this?

Sorry, i seem to struggle when it comes to jsp and servlets. Does that mean to get my list, i just place
request.getAttribute("searchResults");
in my jsp?

Or would you have any simple examples or tutorials that can show me the correct way to do this.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nick Price wrote:thats what i am trying to understand better so i can get rid of the scriplet. I thought that scriplet was getting the forwarded list i forward in my servlet. What i am trying to find out is how i can disply my list in my jsp. I have forwarded the list from my servlet to my jsp, so how do i retrieve this?

You already did it by putting it in the request scope using HttpServletRequest#setAttribute(). The problem lies somewhere else. Your list may be for instance empty. Or the application may have thrown an exception. Debug your code (do a sysout of the list immediately after retrieving it from the DAO), check both the HTML source and the application server logs for some oddities.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nick Price wrote:
Sorry, i seem to struggle when it comes to jsp and servlets. Does that mean to get my list, i just place
request.getAttribute("searchResults");
in my jsp?
No, just ${searchResults} as you already did.

Or would you have any simple examples or tutorials that can show me the correct way to do this.
This is covered by Sun Java EE tutorial. Also at the JSP/Servlet part of my DAO tutorial you can find examples of how the stuff ought to work.
 
Nick Price
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where abouts would i find your DAO tutorial? I cant seem to find it anywhere on this site.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nick Price wrote:Where abouts would i find your DAO tutorial? I cant seem to find it anywhere on this site.
I thought you already know it. I pointed it out to you before: http://forums.sun.com/thread.jspa?messageID=10560020#10560020
 
Nick Price
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you very much for the help.
 
Nick Price
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Somthing has happened since last time, i looked at your further exercises part which helped a lot. I am pretty sure that my list is getting to my servlet, cos i can display it if i add a main to my servlet class. I founf there was a problem when i called it up in my jsp. I was using the wrong name. So i changed it and now i get an error, which seems more hopeful than before. It displays


Then some stacktrace. An then it gives me the root cause


Not understanding as to why it needs to be converted to an integer, or if its trying to convert to an integer. Any clues about this error?
cheers
 
Amit Ghorpade
Bartender
Posts: 2856
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes the clue is that you cannot have something like printResult.nationality where printResult is a String object.
 
Nick Price
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, not quite understanding, printResult shouldnt be a String object, it should be a list of my own object Type. So how can i get rid of this error?
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Shouldn't the items be ${printResults} or so?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!