• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Conversion to JSTL - Help

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone tell on how to convert this into JSTL

I am using JSP 2.0, JSTL 1.1 and tomcat. The "PropertyFileReader" used here reads a property file and returns a HashMap on calling getProperty().
The logic is just to change the CSS, where by user selects the theme in the previous page.

<%
String contextPath = request.getContextPath();
PropertyFileReader propertyFile = new PropertyFileReader("resources.Themes");

String themeId = "1";
themeId = request.getParameter("themeId");

if (themeId == null || "".equals(themeId))
themeId = "1";

String cssName = (String)(propertyFile.getProperty().get(themeId));

pageContext.setAttribute("cssName",cssName);
%>

<html>
<head>
<title>Theme</title>
<link rel="stylesheet" type="text/css" href="<%=contextPath%>/css/Homepage.css">
<link rel="stylesheet" type="text/css" href="<%=contextPath%>/css/${cssName}">
 
Marshal
Posts: 67449
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Hariharan",

There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
JavaRanch Sheriff
 
Bear Bibeault
Marshal
Posts: 67449
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Property file access is handled by the fmt class of JSTL tags. In particular please see the <fmt:message> tag.
 
Hari Maha
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, It worked. Thanks
So the changed code is as follows.

<%
String contextPath = request.getContextPath();
%>

<fmt:setBundle basename="resources.Themes" var="theme" scope="session"/>
<c:set var="themeId" value="1"/>

<c:choose>
<c:when test="${empty param.themeId}">
<c:set var="themeId" value="1"/>
</c:when>

<c:otherwise>
<c:set var="themeId" value="${param.themeId}"/>
</c:otherwise>
</c:choose>

<c:out value="${param.themeId}"/>
<html>
<head>
<title>Theme</title>
<link rel="stylesheet" type="text/css" href="<%=contextPath%>/css/<fmt:message key="${themeId}" bundle="${theme}"/>">

And I think, I have changed my display name correctly?

And I also want to know, if i can also change
<% String contextPath = request.getContextPath(); %>
to JSTL

Thank You in advance
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

And I also want to know, if i can also change <% String contextPath = request.getContextPath(); %> to JSTL


${pageContext.request.contextPath}
 
To get a wish, you need a genie. To get a genie, you need a lamp. To get a lamp, you need a tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic