我在阅读《Spring MVC初学者指南》一书的同时,遇到了一些似乎是请求映射问题的问题。
我在其他类似的Stack Overflow问题中看到并尝试了以下解决方案:
我有以下代码:
目录结构:
家庭控制器。JAVA
package webstore;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class HomeController {
@RequestMapping(value="/")
public String welcome(Model model) {
model.addAttribute("greeting", "Welcome to Web Store!");
model.addAttribute("tagline", "The one and only amazing webstore!");
return "welcome";
}
}
欢迎jsp
<%@ taglib prefix="c"
uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">
<title>Welcome</title>
</head>
<body>
<section>
<div class="jumbotron">
<div class="container">
<h1>${greeting} </h1>
<p>${tagline} </p>
</div>
</div>
</section>
</body>
</html>
DefaultServlet。xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="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.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
<mvc:annotation-driven />
<context:component-scan base-package="com.packt.webstore" />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
web.xml
<web-app version =" 3.0" 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_3_0.xsd">
<servlet>
<servlet-name>DefaultServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>DefaultServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
以下是我在IDE(Spring工具套件)中启动服务器时的整个服务器日志:
Feb 12, 2015 12:32:07 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:webstore' did not find a matching property.
Feb 12, 2015 12:32:07 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server version: Apache Tomcat/7.0.59
Feb 12, 2015 12:32:07 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server built: Jan 28 2015 15:51:10 UTC
Feb 12, 2015 12:32:07 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server number: 7.0.59.0
Feb 12, 2015 12:32:07 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Name: Mac OS X
Feb 12, 2015 12:32:07 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Version: 10.9.2
Feb 12, 2015 12:32:07 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Architecture: x86_64
Feb 12, 2015 12:32:07 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Java Home: /Library/Java/JavaVirtualMachines/jdk1.7.0_60.jdk/Contents/Home/jre
Feb 12, 2015 12:32:07 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Version: 1.7.0_60-b19
Feb 12, 2015 12:32:07 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Vendor: Oracle Corporation
Feb 12, 2015 12:32:07 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_BASE: /Users/richiethomas/Documents/workspace-sts-3.6.3.SR1/.metadata/.plugins/org.eclipse.wst.server.core/tmp0
Feb 12, 2015 12:32:07 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_HOME: /Users/richiethomas/Downloads/apache-tomcat-7.0.59
Feb 12, 2015 12:32:07 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.base=/Users/richiethomas/Documents/workspace-sts-3.6.3.SR1/.metadata/.plugins/org.eclipse.wst.server.core/tmp0
Feb 12, 2015 12:32:07 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.home=/Users/richiethomas/Downloads/apache-tomcat-7.0.59
Feb 12, 2015 12:32:07 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dwtp.deploy=/Users/richiethomas/Documents/workspace-sts-3.6.3.SR1/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps
Feb 12, 2015 12:32:07 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Djava.endorsed.dirs=/Users/richiethomas/Downloads/apache-tomcat-7.0.59/endorsed
Feb 12, 2015 12:32:07 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dfile.encoding=UTF-8
Feb 12, 2015 12:32:07 AM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /Users/richiethomas/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.
Feb 12, 2015 12:32:07 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Feb 12, 2015 12:32:07 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Feb 12, 2015 12:32:07 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 536 ms
Feb 12, 2015 12:32:07 AM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Feb 12, 2015 12:32:07 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.59
Feb 12, 2015 12:32:07 AM org.apache.catalina.deploy.WebXml setVersion
WARNING: Unknown version string [ 3.0]. Default version will be used.
Feb 12, 2015 12:32:08 AM org.apache.catalina.core.ApplicationContext log
INFO: No Spring WebApplicationInitializer types detected on classpath
Feb 12, 2015 12:32:08 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Feb 12, 2015 12:32:08 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Feb 12, 2015 12:32:08 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 1010 ms
从控制器方法中的@RequestMapping(value=“/”)中删除“value=”。
在网上。尝试改变
<servlet>
<servlet-name>DefaultServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
到
<servlet>
<servlet-name>DefaultServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/DefaultServlet-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
您的问题似乎是组件扫描,您扫描了错误的包。您的控制器位于webstore包中,因此更改您的servlet配置:
<context:component-scan base-package="webstore" />
或者将控制器移动到com.packt.webstore
包。
当你的应用被部署时,你应该在日志中看到注册了哪些url映射,然后你就会知道这个修复程序是否有效。
我在我的SpringMVC项目中得到了这个错误。我必须在浏览器中手动添加完整的路径来运行代码,但我不能直接运行它。 web.xml:
在Spring项目中, 警告:org。springframework。网状物servlet。PageNotFound-在名为“appServlet”的DispatcherServlet中找不到URI为[/]的HTTP请求的映射 错误不断发生。我不知道为什么会发生这些错误。 请你帮我... servlet上下文。xml 正如你在下面看到的,我指定了@Controller。 BoardControll
这是我的代码。我不知道这有什么问题。
问题内容: 我已经检查了关于stackoverflow的几乎所有相关文章,但是我无法解决我的问题。 Here is the code: web.xml: spring-servlet.xml: myController: Web Pages/index.jsp: Web Pages/WEB-INF/jsp/hello.jsp: 因此,当我启动该应用程序时,index.jsp已正确加载,但是当我单击
早上,我已经检查了这个问题的大部分答案(在名为DispatcherServlet的DispatcherServlet中找不到URI为的HTTP请求的映射),以及(在名为“DispatcherServlet”的DispatcherServlet中找不到URI为[/ChickenTest/index]的HTTP请求的映射),但我仍然得到“在名为“bmoa”的DispatcherServlet中找不到U
这是我的Spring安全豆 这是我的MVC-dispatcher servlet 这是我的web.xml