我收到了这个错误。
我的 web.xml 有此
<servlet>
<servlet-name>springweb</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/web-application-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springweb</servlet-name>
<url-pattern>/app/*</url-pattern>
</servlet-mapping>
我在web-application-config.xml
中有这个<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
</bean>
<bean name="/Scheduling.htm" class="com.web.SchedulingController"/>
我的com.web.SchedulingController看起来像这样
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.web;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
public class SchedulingController implements Controller{
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
ModelAndView modelAndView = new ModelAndView("/jsp/Scheduling_main.jsp");
modelAndView.addObject("message","Hello World MVC!!");
return modelAndView;
}
}
当我使用网址http://localhost:8080/project1/app/Scheduling.htm点击此控制器时 Scheduling_main.jsp显示但图像显示不正确。 js和css文件也没有被渲染。
我正在访问这样的图片
<img src="jquerylib/images/save_32x32.png" title="Save Appointment">
如果我将servlet定义中的URL映射更改为* .htm,则图像显示正常。你能指出我错过的地方吗?
这是完整的错误消息
WARN [PageNotFound] No mapping found for HTTP request with URI [/mavenproject1/app/jquerylib/images/save_32x32.png] in DispatcherServlet with name 'springweb'
非常感谢。 拉维
答案 0 :(得分:8)
我认为这是因为您尝试通过servlet获取图像(映射为/ app / *)您需要获取静态内容而不使用servlet处理它,例如将图像源设置为
<img src="../jquerylib/images/save_32x32.png" title="Save Appointment">
然后您的图像的真实URI将是/mavenproject1/jquerylib/images/save_32x32.png,它将由您的tomcat按原样返回,无需任何处理。
答案 1 :(得分:2)
我只需在spring默认规则(/ **)之前添加三条规则到tuckey的urlrewritefilter(urlrewrite.xml)来解决问题
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 3.0//EN" "http://tuckey.org/res/dtds/urlrewrite3.0.dtd">
<urlrewrite default-match-type="wildcard">
<rule>
<from>/</from>
<to>/app/welcome</to>
</rule>
<rule>
<from>/scripts/**</from>
<to>/scripts/$1</to>
</rule>
<rule>
<from>/styles/**</from>
<to>/styles/$1</to>
</rule>
<rule>
<from>/images/**</from>
<to>/images/$1</to>
</rule>
<rule>
<from>/**</from>
<to>/app/$1</to>
</rule>
<outbound-rule>
<from>/app/**</from>
<to>/$1</to>
</outbound-rule>
</urlrewrite>
答案 2 :(得分:0)