Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

creating textbox

 
Mayank Yadav
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi..iam very new to jsp, i would like to know how to fetch a value entered in a text box, check box and then display it after clicking a button...
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64698
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"my self",

There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
JavaRanch Sheriff
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64698
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What code have you written so far?
 
Mayank Yadav
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<HTML>
<HEAD>
<TITLE>Submitting Text Fields</TITLE>
</HEAD>

<BODY>
<H1>Submitting Text Fields</H1>
<FORM ACTION="formAction.jsp" METHOD="POST">
Please enter your name:
<INPUT TYPE="TEXT" NAME="text1">
<BR>
<INPUT TYPE="SUBMIT" value="Submit">
<% out.println(request.getParameter("text1")); %>

</FORM>
</BODY>
<HTML>
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64698
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the purpose of the out.print statement in this form html?

Since the form has yet to be submitted, it's got nothing to show.
 
Mayank Yadav
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After clicking the submit button the text written in the textbox should be displayed in the page ...so how should i do this..??
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64698
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you click the submit button control will be passed to the JSP page in the action attribute of the form. Is that another page or this same page?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64698
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Before going any further, I'd highly recommedn that you read this article.
 
Mr. Ravi Yadav
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mayank Yadav wrote:<HTML>
<HEAD>
<TITLE>Submitting Text Fields</TITLE>
</HEAD>

<BODY>
<H1>Submitting Text Fields</H1>
<FORM ACTION="formAction.jsp" METHOD="POST">
Please enter your name:
<INPUT TYPE="TEXT" NAME="text1">
<BR>
<INPUT TYPE="SUBMIT" value="Submit">
<% out.println(request.getParameter("text1")); %>

</FORM>
</BODY>
<HTML>



Question : What if we want to do the same thing (print the "text1" on console) in "Servlet".
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64698
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java code in a JSP? In 2011? Really?

And, as the value of text1 can't be known until after the JSP executes and the page is sent to the browser where the user can enter the value, there is no way to do this.

I suggest you read this article to understand what JSP is and how it works.

 
Mr. Ravi Yadav
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Java code in a JSP? In 2011? Really?

And, as the value of text1 can't be known until after the JSP executes and the page is sent to the browser where the user can enter the value, there is no way to do this.

I suggest you read this article to understand what JSP is and how it works.




What if the text1 is hard coded say like :
<INPUT TYPE="TEXT" NAME="text1" VALUE="My Value">

P.S : I know it might be a silly question, however I wanted to clear this point.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64698
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Still no. To the JSP engine the HTML markup is just template text. It makes as much sense to the JSP engine as wufgwukrfwrfgkuwgfrgfkwrkdkdwgckw.

Have you read the article?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic