0

I have see dozens of that problem here but no solution solved mine. I'm testing Kendo UI in a VERY simple basic java ee dynamic web project. I only have 1 servelet and one JSP. I have used <%@ include file="path" %> just for taking advantage of that tag. Also I have only use doGet from the servlet to return the view. But I still get that error saying :

For my CSS Files

Resource interpreted as Stylesheet but transferred with MIME type text/html

For my javascript files

Uncaught SyntaxError: Unexpected token <

I am using Pivotal Server WITH NO SECURITY CONFIGURATION. My IDE is using the default encoding for ALL types of files (ISO Latin 1) and (UTF -8 for XML)

**Important symptom : ** when I go in the browser with http://localhost:8080/testKendoUI/resources/css/styles/kendo.default.min.css or any other CSS or JS file, I'm redirected to the index.jsp but not to the code of the file.

I have tried <mime-mapping> in web.xml but it did not solve the issue.

Below is my code and some screen shots

Project structure enter image description here

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>dispatcher</servlet-name>
            <servlet-class>com.kendoUI.controllers.dispatcher</servlet-class>
         </servlet>

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

</web-app>

dispatcher servlet

package com.kendoUI.controllers;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@WebServlet("/dispatcher")
public class dispatcher extends HttpServlet {
    private static final long serialVersionUID = 1L;

    public dispatcher() {
        super();
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.getServletContext().getRequestDispatcher("/WEB-INF/views/index.jsp").forward(request, response);
    }


    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

}

headerHTML.jsp

<!DOCTYPE html>
<html>
<head>
    <title>My KendoUI Test App</title>
    <!-- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> -->
    <link type="text/css" rel="stylesheet" href="resources/css/styles/kendo.common.min.css"/>
    <link type="text/css" rel="stylesheet" href="resources/css/styles/kendo.default.min.css"/>
    <link type="text/css" rel="stylesheet" href="resources/css/bootstrap/css/bootstrap.min.css"/>
    <script type="text/javascript" src="resources/js/jquery.min.js"></script>
    <script type="text/javascript" src="resources/js/kendo.all.min.js"></script>
</head>
<body>

taglibs.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="kendo" uri="http://www.kendoui.com/jsp/tags" %>

index.jsp

<%@ include file="/WEB-INF/tags/taglibs.jsp" %>
<%@ include file="/WEB-INF/tags/headerHTML.jsp" %>


<div class="container">
    <div class="row">
        <h1>THIS IS MY TEST</h1>
        <kendo:calendar name="calendar"></kendo:calendar>       
    </div>

</div>


<%@ include file="/WEB-INF/tags/footerHTML.jsp" %>

footerHTMl.jsp

</body>
</html>

Screenshot of error

enter image description here

Bloomberg58
  • 157
  • 1
  • 19
  • @BalusC In addition to making my question as duplicate please explain me a little be so I understand what happened ? How did you go from that error message to [this](https://stackoverflow.com/questions/33248473/change-default-homepage-in-root-path-to-servlet-with-doget) which by the way solved my issue ? – Bloomberg58 Aug 16 '17 at 18:15
  • That's explained in second duplicate link. – BalusC Aug 16 '17 at 18:18
  • @BalusC It's really confusing. When I'm on Spring, I use `/` for my frontcontroller ie only one controller for the app. Here in pure Java EE `/` has a completly different behavior. I still don't understand but I'll keep reading the answers. Thanks – Bloomberg58 Aug 16 '17 at 18:39
  • That is in turn explained and linked in "Front controller" section of the second duplicate link. In short, Spring would fail the same way if you don't configure an URL pattern for static resources. – BalusC Aug 16 '17 at 19:26
  • @BalusC Okay. Thank you BaluC – Bloomberg58 Aug 16 '17 at 22:49

0 Answers0