File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Capturing form element in the scriptlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Capturing form element in the scriptlet" Watch "Capturing form element in the scriptlet" New topic

Capturing form element in the scriptlet

prithvi s zankat

Joined: Jul 18, 2005
Posts: 12
I want to access the HTML form element in the scriptlet(<% %> in the same page. Is it possible? if yes then please tell me how.

look at the example below.
helloworld.jsp is my jsp file.
<%!String javaString;
<form name = "xyz" action="">
<input type = text name = "abc" value="HelloWorld" />
<% i want to assign above declared javaString variable the value of text box, ie. javaString = 'the value of text box'.
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
No way.
HTML is on the client-side, whereas scriplet code runs on the server-side.

Use javascript, instead.
[ September 30, 2005: Message edited by: Adeel Ansari ]
Gareth Faulkner

Joined: Oct 29, 2004
Posts: 22
The scriptlet code will run on the server when the page is being called, so at that point in time, the user will not have had chance to enter any details.

Either use JavaScript or you will need the form to call a Servlet or another JSP page in order to extract the variables from form into Java variables.

I agree. Here's the link:
subject: Capturing form element in the scriptlet
It's not a secret anymore!