1

I created a JSP file. Earlier, it was an html file and the bootstrap was showing perfectly. Now, I changed it to a jsp file. So, when the user enters the URL, it routes via the Dispatcher Servlet and then the user see the jsp.
For some reason, the CSS formatting is not showing:

I am trying to display ipay.jsp:
Here is the file structureenter image description here

The Servlet that maps to this JSP:

package com.tests;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

/*
 * author: Crunchify.com
 * 
 */

@Controller
public class CrunchifyHelloWorld {

    @RequestMapping("/welcome1")
    public ModelAndView helloWorld() {

        String message = "HELLO HEY";
        System.out.println("dpay");
        return new ModelAndView("ipay", "message", message);
    }
}

I changed the structure and code to as follows, still not workingenter image description here

HEre is my servlet.xml

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:mvc="http://www.springframework.org/schema/mvc" 
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans     
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/mvc 
        http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context.xsd">

    <mvc:default-servlet-handler/>

    <mvc:annotation-driven/>

    <mvc:resources mapping="/resources/**" location="/resources/" />
    <context:component-scan base-package="com.stellar,com.tests" />



    <bean id="viewResolver"
        class="org.springframework.web.servlet.view.UrlBasedViewResolver">
        <property name="viewClass"
            value="org.springframework.web.servlet.view.JstlView" />
        <property name="prefix" value="/WEB-INF/jsp/" />
        <property name="suffix" value=".jsp" />
    </bean>

</beans>

Here is my web.xml:

<web-app>
  <display-name>Archetype Created Web Application</display-name>

   <servlet>
        <servlet-name>stellar</servlet-name>
        <servlet-class>
            org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>stellar</servlet-name>

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



</web-app>
TimeToCodeTheRoad
  • 7,032
  • 16
  • 57
  • 70

2 Answers2

2

Again trouble with path. Your default.css is under jsp folder.

Either change the href to jsp\default.css or move the default.css level up.

I would recommend to create a separate css folder and place all the *.css files there. Also adapt your path.

In general WEB-INF is your root. Start paths from there and place your files accordingly.

StanislavL
  • 56,971
  • 9
  • 68
  • 98
1

Copy your default.css under resources folder.

Then add resources mapping in your stellar-servlet.xml under beans tag.

<mvc:resources mapping="/resources/**" location="/resources/" />

The folder structure and url-mapping are completely different things in spring framework. Spring mvc has a urlBasedviewResolver to resolve jsps with JstlView.

İlker Korkut
  • 3,129
  • 3
  • 30
  • 51