java - How to use "css" in the "jsp" in Spring MVC project? -
i working on spring mvc project in trying use css style sheets referencing design jsp page. somehow css files not being picked once hit method in controller..
below jsp file -
<html> <head> <link rel="stylesheet" type="text/css" href="test.css" /> </head> <body> <h1>all header 1 elements red</h1> <h2>all header 2 elements blue</h2> <p>all text in paragraphs green.</p> </body> </html> and below test.css file -
h1 {color:red;} h2 {color:blue;} p {color:green;} and below method in controller class -
@requestmapping(value = "testing", method = requestmethod.get) public map<string, string> testing() { final map<string, string> model = new linkedhashmap<string, string>(); return model; } directory structure -
webapp/ |-- resources/ | +-- css/ | test.css +- web-inf/ +-- views/ testing.jsp
but somehow it's not working me.. there wrong doing here?
update:-
here web.xml file-
<?xml version="1.0" encoding="utf-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" xsi:schemalocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="webapp_id" version="3.0"> <display-name>testweb</display-name> <listener> <listener-class>com.host.webres.resource.env.ebayresourceruntimelistener</listener-class> </listener> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> <welcome-file>index</welcome-file> </welcome-file-list> <servlet> <servlet-name>appservlet</servlet-name> <servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class> <init-param> <param-name>contextconfiglocation</param-name> <param-value>/web-inf/spring/context.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>appservlet</servlet-name> <url-pattern>/testweb/*</url-pattern> </servlet-mapping> </web-app> and below context.xml file -
<?xml version="1.0" encoding="utf-8"?> <beans:beans xmlns="http://www.springframework.org/schema/mvc" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:beans="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:task="http://www.springframework.org/schema/task" xsi:schemalocation=" http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.1.xsd"> <!-- dispatcherservlet context: defines servlet's request-processing infrastructure --> <!-- allow proxys --> <aop:aspectj-autoproxy /> <!-- enables spring mvc @controller programming model --> <mvc:annotation-driven> <mvc:message-converters> <!-- support ajax processing progressive rendering. overrides httpoutputmessage raptorresponsewriter --> <beans:bean class="com.host.terr.kernel.filter.raptorjacksonhttpmessageconverter"/> </mvc:message-converters> </mvc:annotation-driven> <context:component-scan base-package="com.host.terr.config" /> <context:component-scan base-package="com.host.personalization.bullseye.zookeeper.p13nzook.controller" /> <!-- handles http requests efficiently serving static resources in corresponding directory --> <resources mapping="/js/**" location="/js/" /> <resources mapping="/css/**" location="/css/" /> <!-- resolves views selected rendering @controllers .jsp resources in /web-inf/views directory --> <beans:bean class="org.springframework.web.servlet.view.internalresourceviewresolver"> <beans:property name="prefix" value="/web-inf/views/" /> <beans:property name="suffix" value=".jsp" /> </beans:bean> </beans:beans> this exception getting on console browser shows data without css -
404 /testweb/test.css not found /testweb/test.css not found }, correlations : {} }
this css resource issue
please try below
<link rel="stylesheet" type="text/css" href="css/test.css" /> and can see resource if load bowaser.
Comments
Post a Comment