2

I'm working on making an application (developed for tomcat 5.5) to be compatible with tomcat 7 (7.0.27). I'm having problems with jstl, simply tags are not output when I specify:

<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">

in my WEB-INF/web.xml file (previously, the 2.4 version was used).

An example .jsp file:

%@page
   language="java"
   pageEncoding="utf-8"
   contentType="text/html;charset=utf-8"
   buffer="none"
%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="uri:path-to-layout/layout" prefix="layout" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<fmt:bundle basename="com.path.to.resources.Labels">

...

<td><input
name="j_username"
id="j_username" 
maxlength="30" 
accesskey="2" 
type="text"
style="width: 150px;"
value="<c:out value="${pageContext.request.remoteUser}" default="" />" /></td>

Instead of expected output, I receive:

${pageContext.request.remoteUser}

as the value in the text field.

I use JSTL 1.2.1, Tomcat 7.0.27, JSP 2.2. The code compiles, and when I change web-app version in web.xml from 3.0 to 2.4 it works without outputting those values directly (although there are other issues which force me to use 3.0 version). Any ideas what could be the cause of this problem?

tomsky
  • 535
  • 4
  • 11
  • 28
  • try removing -> default="" it looks like you have that inside of the c:out tag. – ChadNC May 25 '12 at 15:58
  • 1
    @ChadNC: default is a valid attribute of c:out. – GriffeyDog May 25 '12 at 16:02
  • What is the result of `${pageContext.request.remoteUser}` if you directly print it using `` tag, that is outside `` tag? It is possible that the value is not stored in the variable that you are using hence it is using the default value. – Logan May 28 '12 at 12:42
  • In other words, JSTL works fine but EL not. To exclude the one and other, does it work when placed outside JSTL tags? E.g. ``. What libraries exactly do you now all have in `/WEB-INF/lib`? @Logan: that returns normally the logged-in user, it's not a custom variable or something. – BalusC May 28 '12 at 13:07
  • Hi, no it still doesn't work if I try – tomsky May 29 '12 at 16:06
  • I have exactly 117 files in mt /WEB-INF/lib directory (all of them are inherited from the project which worked fine on tomcat 5.5) – tomsky May 29 '12 at 16:21
  • The files that I think could be related to this: commons-jexl-1.1.jar, jstl.jar, standard.jar, taglibs-datetime.jar, taglibs-input.jar – tomsky May 29 '12 at 16:31

2 Answers2

4

You mentioned that you were using JSTL 1.2.1, which I assume to be the following ones which are hijacked from the Glassfish server:

  • javax.servlet.jsp.jstl-1.2.1.jar
  • javax.servlet.jsp.jstl-api-1.2.1.jar

However, as per the comments you seem to still have the old JSTL 1.0/1.1 libraries among the 117 files in the /WEB-INF/lib:

  • jstl.jar
  • standard.jar

That would only have conflicted. Remove them.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Hi, thanks for your suggestion. I tried what you said, but after that I cannot compile the project, I get: build.xml:247: java.lang.NoClassDefFoundError: javax/el/ValueExpression – tomsky May 30 '12 at 09:02
  • The above happens when I try to built this project in eclipse. I also tried to remove those files from my tomcat's WEB-INF/lib directory and restart the server, that didn't make any difference, though. – tomsky May 30 '12 at 10:00
  • Then your classpath is apparently more messed up with old EL libraries. The mentioned class is part of JSP/EL 2.1 which is normally already supplied by the servletcontainer itself. It would be helpful if you post a list of all those 117 JARs in `/WEB-INF/lib` anyway. Perhaps the previous developer has placed servlet-container specific libraries in there which is a [no-no](http://stackoverflow.com/a/4076706). By the way, Tomcat doesn't have a `/WEB-INF/lib` directory, but it does have a `/lib` directory and you should **absolutely not** remove any files from there. – BalusC May 30 '12 at 12:30
  • Thanks for your answer. I have actually managed to solve this issue. Instead of using servlet 3.0 declaration, I stuck with the 2.4 and included all the jar library from the old project. What I didn't realize was tomcat 5.5 storing .jars in several different lib folders. The solution was simply to include all of those (well, some of them had to be removed as they causes other problems) into my WEB-INF/lib folder. This seemed to be a problem. Thanks for your detailed explanation (I will up vote and and award you a bounty) – tomsky May 30 '12 at 13:18
0

You need to use single-quotes for the c:out, otherwise you're ending the value attribute of the input tag. Do this instead:

<td><input name="j_username" id="j_username" maxlength="30" accesskey="2"
     type="text" style="width: 150px;" 
     value="<c:out value='${pageContext.request.remoteUser}' default='' />" /></td>
GriffeyDog
  • 8,186
  • 3
  • 22
  • 34
  • 1
    Just tried tried, it actually doesn't make any difference to the output. – tomsky May 25 '12 at 16:12
  • 1
    Does it work without the c:out, just using straight EL, i.e.: value="${pageContext.request.remoteUser}" – GriffeyDog May 25 '12 at 16:23
  • 1
    No, it doesn't make any difference to the output – tomsky May 28 '12 at 08:19
  • While nested quotes can confuse IDEs and developers, this actually doesn't matter to the JSP compiler. The JSP compiler doesn't care about those nested quotes at all when parsing taglibs. All it sees is only the ``. Ultimately the final result is syntactically valid. – BalusC May 28 '12 at 13:11