0

I have built an application web using Spring MVC and JSP using IntelliJ IDEA. It can work well in localhost. And now I am trying to deploy it on to the server using *.war file. And when I try to run the IP address, it can show the main page, but I just realized that it did not load the CSS and js file.

When I try to inspect element. I showed:

  Failed to load resource: the server responded with a status of 500 () style.css:1

this is my pom.xml file:

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.visualisationdataproject</groupId>
  <artifactId>visualisation-dataproject</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>war</packaging>

  <name>visualisation-dataproject Maven Webapp</name>
  <!-- FIXME change it to the project's website -->
  <!--<url>http://www.example.com</url>-->
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>

    <java-version>1.7</java-version>
    <org.springframework-version>4.1.1.RELEASE</org.springframework-version>
  </properties>



  <dependencies>
    <!--dependency-->
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-log4j12</artifactId>
      <version>1.7.21</version>
    </dependency>

    <!--j2ee, servlet、jsp、jstl-->
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>3.1.0</version>
    </dependency>
    <dependency>
      <groupId>javax.servlet.jsp</groupId>
      <artifactId>jsp-api</artifactId>
      <version>2.2</version>
    </dependency>
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>jstl</artifactId>
      <version>1.2</version>
    </dependency>

    <!--mysql-->
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>5.1.35</version>
    </dependency>

    <!--springframework-->
    <!-- Spring Framework -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-core</artifactId>
      <version>5.0.4.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-beans</artifactId>
      <version>5.0.4.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context</artifactId>
      <version>5.0.4.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-jdbc</artifactId>
      <version>5.0.4.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-test</artifactId>
      <version>5.0.4.RELEASE</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-webmvc</artifactId>
      <version>5.0.4.RELEASE</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.springframework/spring-orm -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-orm</artifactId>
      <version>5.0.7.RELEASE</version>
    </dependency>

      <!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
      <dependency>
          <groupId>org.hibernate</groupId>
          <artifactId>hibernate-core</artifactId>
          <version>5.3.2.Final</version>
      </dependency>

    <!--apache.commons-->
    <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>commons-lang3</artifactId>
      <version>3.4</version>
    </dependency>
    <dependency>
      <groupId>commons-fileupload</groupId>
      <artifactId>commons-fileupload</artifactId>
      <version>1.3.1</version>
    </dependency>

    <!--Servlet-Api -->
    <!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>4.0.0</version>
      <scope>provided</scope>
    </dependency>

<!--additional for uplaod-->
      <dependency>
          <groupId>javax.servlet</groupId>
          <artifactId>javax.servlet-api</artifactId>
          <version>3.1.0</version>
          <scope>provided</scope>
      </dependency>
      <dependency>
          <groupId>javax.servlet.jsp</groupId>
          <artifactId>javax.servlet.jsp-api</artifactId>
          <version>2.3.1</version>
          <scope>provided</scope>
      </dependency>

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

      <dependency>
          <groupId>commons-fileupload</groupId>
          <artifactId>commons-fileupload</artifactId>
          <version>1.3.1</version>
      </dependency>

      <!-- File Upload Dependencies -->

      <dependency>
          <groupId>commons-io</groupId>
          <artifactId>commons-io</artifactId>
          <version>2.5</version>
      </dependency>

    <dependency>
      <groupId>com.google.code.gson</groupId>
      <artifactId>gson</artifactId>
      <version>2.8.4</version>
    </dependency>



  </dependencies>

  <build>
    <finalName>visualisation-dataproject</finalName>
      <plugins>
          <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-compiler-plugin</artifactId>
              <configuration>
                  <source>8</source>
                  <target>8</target>
              </configuration>
          </plugin>
      </plugins>
      <resources>
      <!--Said that the java directory under the relevant xml file, properties file compile / package when placed in the resource directory-->
      <resource>
        <directory>${basedir}/src/main/java</directory>
        <includes>
          <include>**/*.properties</include>
          <include>**/*.xml</include>
        </includes>
      </resource>
      <resource>
        <directory>${basedir}/src/main/resources</directory>
      </resource>
    </resources>
    <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
      <plugins>
        <!--Servlet container jetty plugin-->
        <plugin>
          <groupId>org.eclipse.jetty</groupId>
          <artifactId>jetty-maven-plugin</artifactId>
          <version>9.3.10.v20160621</version>
        </plugin>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <configuration>
            <source>1.6</source>
            <target>1.6</target>
          </configuration>
        </plugin>
        <plugin>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-maven-plugin</artifactId>
          <executions>
            <execution>
              <goals>
                <goal>repackage</goal>
              </goals>
            </execution>
          </executions>
          <configuration>
            <executable>false</executable>
          </configuration>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</project>

And this is my spring-mvc-servlet.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans  http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context  http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
    <import resource="classpath:user-beans.xml" />
    <context:component-scan base-package="com.Patient" />
    <context:annotation-config />

    <!--set the resource css, js, image-->
    <mvc:resources mapping="/css/**" location="/WEB-INF/statics/css/"/>
    <mvc:resources mapping="/js/**" location="/WEB-INF/statics/js/"/>
    <mvc:resources mapping="/image/**" location="/WEB-INF/statics/images/"/>

    <mvc:annotation-driven />
    <mvc:default-servlet-handler />



    <!--set beans property of prefix and suffix-->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/views/" />
        <property name="suffix" value=".jsp" />
    </bean>


    <!-- Springmvc file upload node to be configured-->
    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">

        <!-- Maximum Upload Size (In Bytes) - 20 MB -->
        <property name="maxUploadSize" value="20971520" />

        <!-- Maximum Size Of The File In Memory (In Bytes) - 10 MB-->
        <property name="maxInMemorySize" value="1048576" />
        <property name="defaultEncoding" value="UTF-8"/>
        <property name="resolveLazily" value="true"/>
    </bean>

    <!-- File Upload Exception Resolver i.e. In Case Of Exception The Controller Will Navigate To 'error.jsp' & Will Display The Exception Message -->
    <bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
        <property name="exceptionMappings">
            <props>
                <prop key="java.lang.Exception">error</prop>
            </props>
        </property>
    </bean>

</beans>

This is my home.jsp

<%--
  Created by IntelliJ IDEA.
  User: agnesdirgahayupalit
  Date: 27/04/2018
  Time: 12:33
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String reqUserName = request.getParameter("username");
%>
<html lang="en">

<head>
    <title>Welcome - Visualisation Data Wearable Sensor</title>
    <%--<base href="http://staffwww.dcs.shef.ac.uk/people/A.Simons/"/>--%>
    <meta charset="utf-8"/>
    <meta  name="viewport" content="width=device-width, initial-scale=1"/>
    <link rel="stylesheet" href="https://staffwww.dcs.shef.ac.uk/people/A.Simons/campus_only/w3.css"/>
    <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Oswald">
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open Sans">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
    <link rel="stylesheet" href="./css/styles.css" type="text/css">
</head>

<body>
<%--class="w3-content"--%>

    <nav class="w3-topnav w3-black">
        <div class="w3-bar w3-hide-small">
            <%--<a href="./home.jsp" class="w3-bar-item w3-button"><i class="fa fa-home"></i> Home</a>--%>
            <a href="#" class="w3-bar-item w3-button"><i class="fa fa-home"></i> Home</a>
            <%--<a href="./patient/<%=reqUserName%>/searchAssignment" class="w3-bar-item w3-button w3-right"><i class="fa fa-search"></i> Search</a>--%>
        </div>
    </nav>

<header class="w3-row w3-padding w3-light-grey w3-center">
    <%--<div class="w3-col m4 l3">--%>
        <%--<img src="buttons/CloudComputing.png" alt="CloudBase" style="height:100px"/>--%>
    <%--</div>--%>
    <div class="w3-col m8 l12">
        <h6>Welcome to visualization program  <span class="w3-tag"> The University of Sheffield</span></h6>
        <h1 class="w3-xxxlarge"><b>Visualization Data Analytics</b></h1>
    </div>
</header>

<div class="w3-content">
<section class="w3-container w3-white">

    <h1 class="w3-text-gray">Help analysed wearable data</h1>
    <h1 class="w3-jumbo w3-text-dark-gray w3-hide-small"><b>Input the data patient ...</b></h1>

    <!-- Three-up descriptions of individual apps here -->

    <section class="w3-row">

    </section>


    <!-- Second row of Apps -->

    <section class="w3-row" >
        <div class="w3-half w3-padding">
            <div class="w3-card-4 w3-light-grey w3-center">

                <header class="w3-container w3-blue" >
                    <h2>Have not add the data?</h2>
                </header>

                <div class="w3-image w3-padding">
                    <a href="./formAddPatient/<%=reqUserName%>/form">
                        <h6><button class="w3-button w3-white w3-padding-large w3-large w3-opacity w3-hover-opacity-off">Add Data Patient</button></h6>
                    </a>
                </div>

                <div class="w3-container">
                    <p><i class="fa fa-pencil"></i>  Only enter several data, pretty simple.</p>
                </div>

            </div>
        </div>

        <div class="w3-half w3-padding" >
            <div class="w3-card-4 w3-light-grey w3-center">

                <header class="w3-container w3-indigo">
                    <h2>Already add you data?</h2>
                </header>

                <div class="w3-image w3-padding">
                    <a href="./showAllPatient/<%=reqUserName%>/show">
                        <h6><button class="w3-button w3-white w3-padding-large w3-large w3-opacity w3-hover-opacity-off">Show Patient</button></h6>
                    </a>
                </div>


            </div>
        </div>
    </section>

    <br/>
    <section class="w3-row" >
    </section>
</section>
</div>


</body>

</html>

this is my CSS file:

/*this is the css code for common file in view*/

h1,h2,h3,h4,h5,h6 {
    font-family: "Oswald", Arial, "Helvetica Neue", Helvetica, sans-serif;
}
body {
    font-family: "Open Sans", Arial, "Helvetica Neue", Helvetica, sans-serif;
}

.container{
    padding-bottom: 30px;
}

.main{
    padding-bottom: 20px;
}

And also I when I click the 2 button on the home.jsp. It getting error:

javax.servlet.ServletException: Servlet.init() for servlet [spring-mvc] threw exception
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:496)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
    org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
    org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803)
    org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:800)
    org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1463)
    org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1135)
    java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
    org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    java.base/java.lang.Thread.run(Thread.java:844)

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'patientController': Unsatisfied dependency expressed through field 'patientService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'patientService': Unsatisfied dependency expressed through field 'patientDao'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'patientDao' defined in class path resource [user-beans.xml]: Cannot resolve reference to bean 'hibernateSessionFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateSessionFactory' defined in class path resource [user-beans.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
    org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:587)
    org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:91)
    org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:373)
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1344)
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582)
    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:502)
    org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:312)
    org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
    org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:310)
    org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)
    org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:760)
    org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:868)
    org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549)
    org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:676)
    org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:642)
    org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:690)
    org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:558)
    org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:499)
    org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:172)
    javax.servlet.GenericServlet.init(GenericServlet.java:158)
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:496)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
    org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
    org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803)
    org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:800)
    org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1463)
    org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1135)
    java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
    org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    java.base/java.lang.Thread.run(Thread.java:844)

Again, my program is work well when I run in IDEA localhost, instead in the server tomcat when it has been deployed. Any idea why is this happen?

Thank you

  • yes, i have updated it, please check –  Aug 29 '18 at 08:53
  • this does not work, after i modified, and deploy it again. The error just change to : `Failed to load resource: the server responded with a status of 404 ()` –  Aug 29 '18 at 10:00
  • 1
    Actually you do not need to publish the CSS file. the problem is not about what you type in CSS. You even do not need to show about JSP file. II will show you the answer below – Agnes Palit Aug 29 '18 at 12:37
  • 1
    Try this : https://stackoverflow.com/a/43574427/4016288 and put it on your pom.xml file. – Agnes Palit Aug 29 '18 at 12:37
  • Yes, you are right. Thank you –  Aug 29 '18 at 12:42
  • 1
    The thing is, you should aware about the error type if the error code error is 404 it means there is a problem about set directory to asset file. But if the error code is 500 it means there is a problem of the server, in your case it probably about JDK integration – Agnes Palit Aug 29 '18 at 12:44
  • Yes, a brilliant solution. Thanks for the advice. –  Aug 29 '18 at 12:45

1 Answers1

0

According the link that I sent you before, you need to add these code in you pom.xml file:

<dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.2.11</version>
</dependency>
<dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-core</artifactId>
    <version>2.2.11</version>
</dependency>
<dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-impl</artifactId>
    <version>2.2.11</version>
</dependency>
<dependency>
    <groupId>javax.activation</groupId>
    <artifactId>activation</artifactId>
    <version>1.1.1</version>
</dependency>
Agnes Palit
  • 246
  • 1
  • 5
  • 22