| 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: 56529
|
|
"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
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56529
|
|
|
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> <c therwise> <c:set var="themeId" value="${param.themeId}"/> </c therwise> </c:choose> <c ut 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: 14685
|
|
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
|
 |
 |
|
|
subject: Conversion to JSTL - Help
|
|
|