This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Servlets and the fly likes Passing values from JSP page to Java program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Passing values from JSP page to Java program" Watch "Passing values from JSP page to Java program" New topic
Author

Passing values from JSP page to Java program

Brian Mulvany
Greenhorn

Joined: Oct 19, 2004
Posts: 28
I am creating a cd search engine website. I want a user to be able to type in the name of the cd they are looking for and I will have programs in the background doing the searching for them. Eventually I will search several websites but for now Ill settle just for searching CDWOW and returning their results.
I have managed to create several Java classes that search http://www.cdwow.ie for an album and return the results back as XML but within the Java program. I want the user to be able to use a JSP webpage with a form to be able to search for whatever cd they want. When they type in U2 for example I want U2 to be passed into the Java program. Also I would like the results of the seach that are in XML to be in abrand new XML or HTML file.
Thanks
Brian Mulvany
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
you want to pass the searched string into your java prgram from a jsp page, right?

couldn't we integrate both your program and your jsp. i mean could this architecture becomes like.

jsp - - -- -> servlet for handling request/response(as you posted this here) - -- -> your program.

how about this. i think you should be more specified where you need help or idea.

thanks.
Brian Mulvany
Greenhorn

Joined: Oct 19, 2004
Posts: 28
Hi again
Im sorry if I am annoying you.
I just have a quick question. As I am quite new to this how do I integrate my Java into my a JSP servlet. If somebody could tell me where I can learn about how to do this I would greatly appreciate it.
Also the programs I have created is running in JBuilder. It outputs the search results in xml format. I want to know how to get the results into a new JSP or XML page. This could be the same idea as inputting the search results.
Any help is greatly appreciated.
Thanks
Brian
bmulvany@gmail.com
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
you probably have to get rid of your main() method of your program and any UI associated with it. Now your UI would be a JSP page and a Servlet will control your program by request/response mechanism. your classes(POJO which you already have with you) would work as model, where you have your logic stuff.

Moreover I would like to refer you to J2EE Tutorial from java.sun.com. I hope it will guide you through quite quick. For some J2EE web tier fundamentals you can get a book from theserverside.com for free.

cheers.
Sonny Gill
Ranch Hand

Joined: Feb 02, 2002
Posts: 1211

Brian,

A Java program is basically a Java class, and you pass values to a Java program by calling a method on that class, passing in the arguments that are the values used in that method.

Something like myCDSearchObject.getInfoOnCd("U2")
You could make a call like that from a JSP, but it is preferrable to do so from a servlet, and use JSP's only for presenting the data retrieved.

If you havent had a lot of experience in Java, I'd suggest that you start small, get one bit working before you move on to the next bit. For example, code your Java class first that is going to perform the actual search, test that it is working by printing the information retrieved to the console or to a text file, and then worry about how to call it from a Servlet.

Cheers.


The future is here. It's just not evenly distributed yet. - William Gibson
Consultant @ Xebia. Sonny Gill Tweets
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Passing values from JSP page to Java program
 
Similar Threads
XML Searching via java
Searching other websites
Web.xml files
Passing values from JSP page to Java program
Please Suggest API's for interpreting a .xmi file