• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Passing Variable from JSP to JAVA

 
Eric Tan
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can anyone give me an idea on how to get a user input from jsp, pass it into the java page and then manipulate the value to be added into the database....

thanks...
 
pascal betz
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this would fit more in the Serlvet Forum.


The HTML Page (no matter with wath technology you generate it, be it JSP, PHP, ...) "lives" in the users browser.
To grab user input you need a form and input elements in the HTML page. When the submit button is clicked, then the browser sends the form data to the URL specified in the action attribute of the form.

You need to have something (a Servlet/JSP) "listening" on that URL. The servlet can access the form data through the HttpServletRequest Object (getParameter()/getParameters() methods) and insert the values in a DB, print them... whatever you want. Then the Servlet redirects or forwards to a result page. Voila....

hope this helped...

pascal
 
Eric Tan
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks alot for the info but if i want to avoid using servlets? can i use like javabean? where i play around with the setter and getter method? where after i post out the value in the textbox from the user input and set it to a variable. is java able to retrieve it out using get method and manipulate it?


thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64958
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Eric Tan:
but if i want to avoid using servlets?


Why? They're the right tool for the job.
 
Eric Tan
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it's because my boss told us to use javabeans. she said it's because servlets is quite difficult and we are starting to learn java. so she said scared that we might not get the concept as compared to javabean
 
Eric Tan
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it's because my boss told us to use javabeans. she said it's because servlets is quite difficult and we are starting to learn java. so she said scared that we might not get the concept as compared to javabean
 
Eric Tan
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it's because my boss told us to use javabeans. she said it's because servlets is quite difficult and we are starting to learn java. so she said scared that we might not get the concept as compared to javabean
 
Eric Tan
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry that there was a repetition. it is because just now my dsl line was very unstable and i click a few times. didn't know that it repeatly posted my post. sorry about that!!
 
wise owen
Ranch Hand
Posts: 2023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

You need to have something (a Servlet/JSP) "listening" on that URL. The servlet can access the form data through the HttpServletRequest Object (getParameter()/getParameters() methods) and insert the values in a DB, print them... whatever you want. Then the Servlet redirects or forwards to a result page.


JSP is a "servlet". You can ignore or replace "Servlet" to "JSP" in the above statement.
 
Eric Tan
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok. i will give it a thought and work on it. thanks alot.
if anyone has any links that may help me, do post for me please?
thanks alot!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic