Bude10
Bude10

Reputation: 13

Tomcat doesn't interpret jsp syntax

In eclipse I created a new dynamic web project. After converting to maven I added a tomcat v8 server for deploying. But from the beginning it's just possible to display plain html-code. It seems like all jsp syntax isn't interpreted and neglected.

Home.jsp

<html>
    <body>
        <jsp:include page="navigation.jsp"></jsp:include>   
        <c:forEach begin="1" end="3" var="Test">
            <c:out value="${val}"/>
        </c:forEach>
    </body>
</html>

Navigation.jsp

<nav>
    <div>Navigation</div>
</nav>

This displays nothing in the browser. After adding a jsp directive

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

The whole jsp-file with plain html tags is displayed. Any suggestions what's missing?

POM.xml

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>jstl</artifactId>
    <version>1.2</version>
</dependency>
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>servlet-api</artifactId>
    <version>2.5</version>
    <scope>provided</scope>
</dependency>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 
         http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">

  <servlet>
        <servlet-name>website</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/website.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>website</servlet-name>
        <url-pattern>/</url-pattern>
        <url-pattern>*.jsp</url-pattern>
    </servlet-mapping>

    <jsp-config>
        <jsp-property-group>
            <url-pattern>*.jsp</url-pattern>
            <scripting-invalid>true</scripting-invalid>
        </jsp-property-group>
    </jsp-config>

</web-app>

Upvotes: 1

Views: 943

Answers (1)

Serge Ballesta
Serge Ballesta

Reputation: 148910

You are explicitely mapping *.jsp to SpringFramework DispatcherServlet. I do not know why you have written that, but it is the cause of what happens: the jsp files are normally interpreted by tomcat default server which has lowest priority. If any other servlet binds them, this other servlet will get them.

The fix is to just use:

<servlet-mapping>
    <servlet-name>website</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

Upvotes: 1

Related Questions