wood burning stoves 2.0*
The moose likes JSP and the fly likes Setting Value Parameter of HTML tags Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Setting Value Parameter of HTML tags" Watch "Setting Value Parameter of HTML tags" New topic
Author

Setting Value Parameter of HTML tags

Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Is the only way to set Value Parameters of HTML tags is to use scriplets?
value=<% request.getParameter("SomeParam").toString(); %>
Thanks.


GenRocket - Experts at Building Test Data
Vijay S. Rathore
Ranch Hand

Joined: Oct 29, 2001
Posts: 449
You can use JavaScript also to initialize form elements during onload on the <body> tag.


SCJP, SCJD, SCWCD1.4, IBM486, IBM484, IBM 483, IBM 287, IBM141, IBM Certified Enterprise Developer - WebSphere Studio, V5.0
Author of IBM 287 Simulator Exam
Paco Martinez
Greenhorn

Joined: Jul 30, 2003
Posts: 1
Instead of a scriplet you can use an Expression like this
value=<%= request.getParameter("SomeParam").toString() %>
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Originally posted by Paco Martinez:
Instead of a scriplet you can use an Expression like this
value=<%= request.getParameter("SomeParam").toString() %>

Yeah, that's not much different. In fact, take away the = sign and it's the same thing. I still think of those as scriplets.
And javascript?? No way..
maybe I should use Velocity instead of JSP. HA.
But seriously, is this really what everyone does? <% %> for setting value params?
Andrea Steelman
Author
Greenhorn

Joined: Jun 10, 2003
Posts: 5
If you have access to JSTL, you can use a JSTL tag as follows:
value=<c ut value="${param.SomeParameterName}"/>
To use this JSTL tag, you also need a taglib directive in the JSP as follows:
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
JSTL does remove most of the scriptlet code from your JSPs. However, to use it, you must use a server that supports it. You may also have some configuration details to take of.


<a href="http://www.murach.com/books/jsps" target="_blank" rel="nofollow">Murach's Java Servlets and JSP</a>
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Originally posted by Andrea Steelman:
If you have access to JSTL, you can use a JSTL tag as follows:
value=<c ut value="${param.SomeParameterName}"/>
To use this JSTL tag, you also need a taglib directive in the JSP as follows:
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
JSTL does remove most of the scriptlet code from your JSPs. However, to use it, you must use a server that supports it. You may also have some configuration details to take of.


Speaking of JSTL and your book. I know that you don't go in depth into JSTL from another post. But do you use it throughout your examples? Or do you just use Scriplets.
Personally, I think scriplets were the worst thing ever allowed in JSP pages and I wish they would just disallow them in future versions.
Andrea Steelman
Author
Greenhorn

Joined: Jun 10, 2003
Posts: 5
Our book just uses scriptlets. However, I'm sure the next revision will cover JSTL.
One of the problems that we found with JSTL was that at the time of writing the text, Tomcat didn't support it very well. And to do JSP programming, you need to know how to work with scriptlets, regardless if you like them or not.
I agree with you that scriptlets are messy and their use should be minimized as much as possible. In fact, we designed our book to use the MVC pattern to its fullest. When you use this pattern, you can eliminate the need for most scriptlets in your JSPs.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Setting Value Parameter of HTML tags
 
Similar Threads
Set the value in html:select tag
Problem with TEXTAREA
Outputting html text
Drop down list value
Struts layout:select