aspose file tools*
The moose likes JSP and the fly likes Conversion to JSTL  - Help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Conversion to JSTL  - Help" Watch "Conversion to JSTL  - Help" New topic
Author

Conversion to JSTL - Help

Hari Maha
Greenhorn

Joined: Oct 13, 2004
Posts: 11
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}">
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60053
    
  65

"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


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60053
    
  65

Property file access is handled by the fmt class of JSTL tags. In particular please see the <fmt:message> tag.
Hari Maha
Greenhorn

Joined: Oct 13, 2004
Posts: 11
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>

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

<cut 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
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

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

${pageContext.request.contextPath}


[My Blog]
All roads lead to JavaRanch
 
wood burning stoves
 
subject: Conversion to JSTL - Help
 
Similar Threads
Scriptless JSP
how to call css file from a jsp
Style Sheet Problem in Websphere
Struts help
jsp and style sheets