1

I have been searching for this nightmare a lot and nothing worked out for me so far. I know that there are lots of discussions about this topic, but I would not post it here, if I found reasonable solution.

The problem is, I want to use Spring's internationalization/localization in my web application (JSP pages) and backend has no problems so far. When I added JSTL dependencies to my pom file, everything in JSP page is just being copied to the browser. I could not find the solution yet and I do not know the problem neither. No errors, no complains, no warnings.

I am using Javax Servlet 3.0.1(also tried 3.1.0), JSTL 1.2 (also tried 1.2.1), Tomcat 7.0.55 (also tried 7.0.27).

Following URLs seems promising, however still I am failing:
Fix maven JSTL 1.2.1 dependency so maven-war-plugin doesn't package JARs that offend Tomcat 7
Standard way of adding JSLT 1.2.1 in a Maven Project?
http://www.murraywilliams.com/2011/11/running-jstl-1-2-on-tomcat-7-using-maven/comment-page-1/#comment-138613
Tomcat 7 and JSTL

My simple .jsp page:

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
    <div>
        <label><spring:message code="test.message"/></label>
    </div>
</body>
</html>

Dependencies in my pom file:

    <!--Javax-->
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-web-api</artifactId>
        <version>7.0</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.0.1</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
    <groupId>javax.servlet.jsp</groupId>
    <artifactId>javax.servlet.jsp-api</artifactId>
    <version>2.3.1</version>
    </dependency>        
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish.web</groupId>
        <artifactId>jstl-impl</artifactId>
        <version>1.2</version>
        <exclusions>
            <exclusion>
                <artifactId>servlet-api</artifactId>
                <groupId>javax.servlet</groupId>
            </exclusion>
            <exclusion>
                <artifactId>jsp-api</artifactId>
                <groupId>javax.servlet.jsp</groupId>
            </exclusion>
            <exclusion>
                <artifactId>jstl-api</artifactId>
                <groupId>javax.servlet.jsp.jstl</groupId>
            </exclusion>
        </exclusions>
    </dependency>

   <!--Test-->
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.8.8</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.17</version>
    </dependency>

    <!--Logging-->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>${slf4j.version}</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>${slf4j.version}</version>
        <type>jar</type>
        <exclusions>
            <exclusion>
                <artifactId>log4j</artifactId>
                <groupId>log4j</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.17</version>
    </dependency>

    <!--Database connectivity-->
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-dbcp2</artifactId>
        <version>2.0</version>
    </dependency>

    <!--Apache Tomcat-->
    <dependency>
        <groupId>org.apache.tomcat</groupId>
        <artifactId>tomcat-catalina</artifactId>
        <version>${tomcat.version}</version>
        <scope>provided</scope>
    </dependency>

    <!--Hibernate-->
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>${hibernate.version}</version>
    </dependency>

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>${hibernate.version}</version>
    </dependency>

    <!--PostgreSQL-->
    <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>9.3-1100-jdbc41</version>
    </dependency>

    <!--Spring Framework-->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aop</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context-support</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-jdbc</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
        <version>${spring.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-tx</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>${spring.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${spring.version}</version>
    </dependency>

My web.xml file content:

<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">
<error-page>
    <error-code>404</error-code>
    <location>/webresource/staticPage/pageNotFound.html</location>
</error-page>
<error-page>
    <error-code>408</error-code>
    <location>/webresource/staticPage/sessionTimeout.html</location>
</error-page>
<error-page>
    <error-code>500</error-code>
    <location>/webresource/staticPage/internalError.html</location>
</error-page>

<jsp-config>
    <jsp-property-group>
        <url-pattern>*.jsp</url-pattern>
        <el-ignored>false</el-ignored>
    </jsp-property-group>
</jsp-config>

I am using web.xml only for error pages, everything else (Spring, etc..) is configured in Java based configurations without any XML files.

How can I solve this issue, is there anybody faced such issue before?

Community
  • 1
  • 1
CacheCort
  • 33
  • 1
  • 6
  • What exactly do you mean by "...everything in JSP page is just being copied to the browser"? – Ascalonian Jan 06 '15 at 16:55
  • All the tags in .jsp pages are copied to the view as they are. In other words, when I run my let's say login.jsp page, all HTML page content is just copied to the view which means bunch of texts. – CacheCort Jan 06 '15 at 17:07
  • So instead of generating the page, it's just returning back the text out of the JSP itself? You've included the `standard.jar`and the other JAR files needed in the classpath, correct? – Ascalonian Jan 06 '15 at 17:11
  • Yes, it is returning JSP text itself and yes again other JARS are needed in classpath. – CacheCort Jan 06 '15 at 20:04

1 Answers1

1

Finding the right java libraries on maven, especially for jsp, is a royal pain, i'm using these in my pom.xml and it's working okay, try this.

<!-- Standard JSP libraries -->
<dependency>
    <groupId>javax.servlet.jsp</groupId>
    <artifactId>jsp-api</artifactId>
    <version>2.2.1-b03</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>javax</groupId>
    <artifactId>javaee-web-api</artifactId>
    <version>7.0</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>org.glassfish.web</groupId>
    <artifactId>javax.servlet.jsp.jstl</artifactId>
    <version>1.2.1</version>
</dependency>
<dependency>
    <groupId>javax.servlet.jsp.jstl</groupId>
    <artifactId>jstl-api</artifactId>
    <version>1.2-rev-1</version>
</dependency>
Zachary Craig
  • 2,192
  • 4
  • 23
  • 34
  • Correction: "especially for Tomcat". – BalusC Jan 07 '15 at 08:15
  • Heh, i suppose so, OP could use TomEE but its still a pain to get the code to look right to your ide without the proper libraries. – Zachary Craig Jan 07 '15 at 08:17
  • Out of curiousity, ive seen you around on a lot of the really big answers here, do you have a servlet engine you would recommend that's better than the others in some way? – Zachary Craig Jan 07 '15 at 08:19
  • zack6849, your suggestion did not work. My Tomcat started to complain about "Linkage error" which means wrong version of javax.servlet is picked. It continued failing even if I excluded javax.servlet from jstl dependencies. Any clue? – CacheCort Jan 07 '15 at 17:56
  • Huh, that's really strange, which tomcat version are you on? I'm using those very same libraries and it worked just fine for me on tomcat 7 and 8 – Zachary Craig Jan 07 '15 at 17:57
  • I am running Tomcat 7.0.55. My Tomcat is not standalone, it is Maven's embedded one. But I do not think because of this I am stuck. – CacheCort Jan 08 '15 at 15:38
  • Maven doesn't have an embedded tomcat to my knowledge – Zachary Craig Jan 08 '15 at 23:19
  • 1
    Finally I got it working. It seems jsp-api also should be excluded from the jar. Thanks anyways.. – CacheCort Jan 09 '15 at 15:09