0

I have a java project a company send to me, I must use the REST services in this project.

I upload some files, but java only see the index.jsp file. I try to use even a index.html file, but it is not seen.

I need to import css and js files inside the html, but they are not found.

Do I need to specify what kind of files the browser can show? or something like this?

This is the web.xml code

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app id="WebApp_ID">
    <display-name>SRA</display-name>

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

    <servlet-mapping>
        <servlet-name>mvc-dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
    <welcome-file-list>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>index.html</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
    </welcome-file-list>
</web-app>

What can I do?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Pablo
  • 9,424
  • 17
  • 55
  • 78
  • just to be sure, you know that's not a basic java project but for an java enterprise application server? – Dennis Kriechel Dec 05 '15 at 17:23
  • Is a basic java project, with some services.. it has the jar file and src folder – Pablo Dec 05 '15 at 17:24
  • web.xml files are special config file for enterprise servers such as weblogic, tomcat, websphere, glassfish or jboss, are you using one of them? – Dennis Kriechel Dec 05 '15 at 17:25
  • How are you trying to access these files, are they pages too? – Perdomoff Dec 05 '15 at 17:26
  • sorry, I misunderstand. it's a tomcat.. when I load `localhost:8080/SRA` it shows the index.jsp file. but if I rename to index.html, it returns 404 – Pablo Dec 05 '15 at 17:27
  • the files are other pages, and JS/CSS files – Pablo Dec 05 '15 at 17:27
  • Create a Webcontent folder under SRA and create 2 more for your js files and css files like : SRA/Webcontent/JS, include these files in the html or jsp files in your project also. – Perdomoff Dec 05 '15 at 17:32
  • I dont have any SRA folder.. it's the `webapp` folder. I have created a webcontent folder inside.. It still the same, if index.jsp is inside it finds it, but index.html, wont find – Pablo Dec 05 '15 at 17:35
  • Other page or file. using index.jsp, I cannot import css or js in the same folder – Pablo Dec 05 '15 at 17:40
  • Do I have to map the files somehow? – Pablo Dec 05 '15 at 17:50

2 Answers2

1

To change index.html from being welcome page add this to your web.xml:

<welcome-file-list>
    <welcome-file>[YourJsp.jsp</welcome-file>
</welcome-file-list>

Or you can forward the browser to your page from your html by adding this to your head tag:

< meta http-equiv="refresh" content="0; url=menu.jsp" / >

For the js and css , include the css and js files in your jsp, taking into consideration the folder structure of your project:

css:

< link rel="stylesheet" type="text/css" href="assets/css/login.css"/ >

js:

< script type="text/javascript" src="assets/jsfiles/index.js">

Perdomoff
  • 938
  • 2
  • 7
  • 26
1

The solution was to add this to my web.xml file

    <servlet-mapping>
        <servlet-name>default</servlet-name>
        <url-pattern>*.css</url-pattern>
    </servlet-mapping>

    <servlet-mapping>
        <servlet-name>default</servlet-name>
        <url-pattern>*.js</url-pattern>
    </servlet-mapping>

    <servlet-mapping>
        <servlet-name>default</servlet-name>
        <url-pattern>*.html</url-pattern>
    </servlet-mapping> 
Pablo
  • 9,424
  • 17
  • 55
  • 78