Java 找到Spring NoHandler,尽管警告正确指向应该处理我的视图的JSP
我的web.xml如下所示Java 找到Spring NoHandler,尽管警告正确指向应该处理我的视图的JSP,java,spring,jsp,spring-mvc,web.xml,Java,Spring,Jsp,Spring Mvc,Web.xml,我的web.xml如下所示 <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:
<?xml version="1.0" encoding="UTF-8"?>
<web-app
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
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_3_0.xsd"
id="Your_Webapp_ID" version="3.0">
<display-name>Spring MVC Application</display-name>
<servlet>
<servlet-name>MyMVCAppCustom</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>MyMVCAppCustom</servlet-name>
<url-pattern>*.app</url-pattern>
</servlet-mapping>
</web-app>
真正奇怪的是SPRING进入了我的控制器方法,进入了我的视图解析器,很明显,我的jsp文件位于/DynWebProj/WEB-INF/springMVCjsps/MyHello.jsp的这个位置,但它声称那里没有处理程序!!!我甚至从我的控制器类收到一条system.out消息
printHello3 {message=hello Hello Spring MVC Framework!}
在tomcat控制台中,它也可以加载所有内容
INFO [localhost-startStop-1] org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.registerHandlerMethod Mapped "{[/bingo],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String code.xander.mvc.MyHelloController.printHello3(org.springframework.ui.ModelMap)
INFO [localhost-startStop-1] org.springframework.web.servlet.FrameworkServlet.initServletBean FrameworkServlet 'MyMVCAppCustom': initialization completed in 1931 ms
我的浏览器url是
http://localhost:8080/DynWebProj/bingo.app
我真的很慌乱,不知所措,因为我已经在小跑中挣扎了三天了。奇怪的是,它突然开始工作,现在却停止了。让我抓狂的是这个问题的量子行为
如果你已经读到了这里,我还可以添加我的控制器类
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class MyHelloController {
@RequestMapping(value = "/bingo", method = RequestMethod.GET)
public String printHello3(ModelMap model) {
model.addAttribute("message", "hello Hello Spring MVC Framework!");
System.out.println("printHello3 " + model);
return "MyHello";
}
}
在这里添加了我的SpringMVCServlet配置xml文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
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-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-3.0.xsd">
<mvc:annotation-driven />
<context:component-scan base-package="code.xander.mvc" />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/springMVCjsps/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
正如您所看到的,即使Spring+Tomcat不呈现我的页面。警告正好映射到我的jsp页面所在的位置。。。。。所以,我无法理解为什么它不能呈现它
警告[http-apr-8080-exec-10]org.springframework.web.servlet.DispatcherServlet.nohandler在名为“MyMVCAppCustom”的DispatcherServlet中未找到URI为[/DynWebProj/web-INF/springMVCjsps/MyHello.jsp]的http请求的映射
DynWebProj是我的应用程序的web根目录。我用了eclipse。运行时以及创建WAR文件并部署到tomcat webapps目录时,我都会收到相同的消息。告诉我们您是如何在spring bean或完整配置文件中配置ViewResolver bean的。@Rembo已经添加了我的spring配置文件Add&并重试。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
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-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-3.0.xsd">
<mvc:annotation-driven />
<context:component-scan base-package="code.xander.mvc" />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/springMVCjsps/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>