JSP / HTML doubt ...
Hi every one!
My doubt may seem to be a waste doubt, but its a doubt,so..,
Can we use JSP tags(like <%,<%=) in a servlet program.
And can we use a JSP tag in between or inside a html tag as.,
<a href=my.html name=<%=val%> >Hi</a>
,,where val is a string object holding some string say Hi.Can we use like this?
Plz guide me! Thnkz in advance...
[413 byte] By [
me_n_javaa] at [2007-11-26 18:05:31]

# 1
I cannot understand your first question ? Why would you want to render jsp tags inside a servlet program ?
For second part, jsp tags can be included within html tags and the html property takes the value within the jsp tag
<%
String name ="DemoUser"
%>
<input type="text" value="<%=name%>"/>
Long time i have not used jsp ... hope this helps
# 2
[nobr]Yes, like Yogesh mentioned it is possible to include a JSP expression
<%=someVariable%>
inside the value attribute of an HTML tag.
However, there is a new and improved way of doing this. In case you are using the latest versions of everything - JSP 2.0 , Servlet 2.4 etc
instead of using a JSP expression like this <%=someVariable%>
, now you can do it in a much simpler syntax with EL like this ${someVariable}
If you install JSTL 1.1 and configure it , there are much simpler and better ways to do things with JSPs now.
For example this JSP scriptlet :
<%
for (int i=0; i < 10; i++){
out.println(i);
}
%>
could be written in JSTL inside a JSP as
<c:forEach begin="1" end="10" var="index" step="1">
${index} <br/>
</c:forEach>
The above is just a small example and doesn't show all the benefits of JSTL, but when the application grows large if one uses just JSP scriptlets and expressions the code becomes unmanageable.
With JSTL the code looks much cleaner , simpler as it encapsulates all business logic to the business layer.
If you are new to JSPs then you can get familiar with scriptlets and expressions, but I encourage you to make use of the benefits of JSTL after you become familiar with the basics of JSPs.
Message was edited by:
appy77[/nobr]