TechnoBuzz

A Techno Blog, mainly about Java

Moving past scriplets

In the early days, while working in JSP files, the approach was to use scriplets to present server side data. Such as

Scriptlet <% code %>
– Code is inserted in service method.

JSP Expression <%= expression %>
– Expression is evaluated and placed in output.

Insert a help message into jsp file
<%
String s3 = new String();
s3 = s3 + “XYZ” ;
out.print(“<!– ” + s3 + ” –>”);
%>

Moreover, to generate javascript inside a JSP, you might do something like:

out.print(“<script>” + “alert” + “(‘” +situation.getValue() + “‘)” + “</script>”);

JSTL technology followed JSP (or even the Struts tag libraries) .

These objects allow for access to any variables that are held in the particular JSP scopes. Objects include:

  • pageScope
  • requestScope
  • sessionScope
  • applicationScope

${sessionScope.loginId} will return the session-scoped attribute named LoginId, or null if the attribute is not found.

<c:if test=”${someTest}”> Content</c:if>

<c:set var=”string1″value=”${item.value}” />

< c:out value=”${‘dmb: ‘} ${string1}” escapeXml=”false”/ >

Now, for javascript jstl integration:

var totRec = ‘<fmt:formatNumber type=”number” value=”${myCount}” />’;

 

Advertisements

January 6, 2013 - Posted by | Uncategorized

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: