Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Setting Value Parameter of HTML tags

 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the only way to set Value Parameters of HTML tags is to use scriplets?
value=<% request.getParameter("SomeParam").toString(); %>
Thanks.
 
Vijay S. Rathore
Ranch Hand
Posts: 449
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use JavaScript also to initialize form elements during onload on the <body> tag.
 
Paco Martinez
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Instead of a scriplet you can use an Expression like this
value=<%= request.getParameter("SomeParam").toString() %>
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic