大家好,我的问题是这样的。
自己搭建了SpringMVC + Spring + Hibernate 框架。
结果在JSP中引用CSS等静态文件的时候遇到了404的问题。
以下是问题的截图。以及配置文件的信息。
还有就是我查了很多资料。SpringMVC加载静态资源的三种配置我都已经试过了但是都不好使。
比如这个链接的内容 三种方式都不好使。
问题情况如下:
项目结构:
SpringMVC配置文件:
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd">
expression="org.springframework.stereotype.Controller" />
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
web.xml:
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
index.jsp
contextConfigLocation
classpath:applicationContext.xml
org.springframework.web.context.ContextLoaderListener
dispatcherServlet
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath:springmvc.xml
1
dispatcherServlet
/
characterEncodingFilter
org.springframework.web.filter.CharacterEncodingFilter
encoding
UTF-8
characterEncodingFilter
/
log4jConfigLocation
classpath:log4j.properties
log4jRefreshInterval
6000
org.springframework.web.util.Log4jConfigListener
openSession
org.springframework.orm.hibernate4.support.OpenSessionInViewFilter
openSession
/*
jsp:
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
My JSP 'work_info.jsp' starting pageWELCOME TO WORKSPACE
Controller:
//就只粘贴了有用的部分
package com.whr.Controller;
import java.sql.Date;
import java.util.List;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import com.whr.Entity.Work;
import com.whr.Service.WorkService;
@Controller
@RequestMapping("/work")
public class WorkController {
@Autowired
private WorkService workService;
private static Logger logger = Logger.getLogger(WorkController.class);
@RequestMapping("/index")
public String workIndex()
{
return "testIndex";
}
@RequestMapping("/index2")
public String workIndex2()
{
return "work";
}
大概情况就是这样的了。
弄了两天了,方法试了好多,简直焦头烂额。各位大神帮帮忙看看吧,不胜感激!