我试图测试Spring MVC,并编写了以下代码:
web.xml:http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd“version=”3.0“>
<display-name>To do List</display-name>
<welcome-file-list>
<welcome-file>login.do</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/todo-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/spring-mvc/*</url-pattern>
</servlet-mapping>
</web-app>
<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-4.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">
<context:component-scan base-package="com.ezmsip" />
<mvc:annotation-driven />
</beans>
package com.ezmsip.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class LoginController {
@RequestMapping(value="/login")
@ResponseBody
public String sayHello() {
return "Hola Mundo";
}
}
HTTP Status 404 - /spring-mvc/login
type Status report
message /spring-mvc/login
description The requested resource is not available.
Apache Tomcat/8.0.39
Tomcat控制台日志:
nov 29, 2016 10:07:47 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:login' did not find a matching property.
nov 29, 2016 10:07:47 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:first-web-app' did not find a matching property.
nov 29, 2016 10:07:47 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server version: Apache Tomcat/8.0.39
nov 29, 2016 10:07:47 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server built: Nov 9 2016 08:48:39 UTC
nov 29, 2016 10:07:47 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server number: 8.0.39.0
nov 29, 2016 10:07:47 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Name: Windows 7
nov 29, 2016 10:07:47 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Version: 6.1
nov 29, 2016 10:07:47 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Architecture: amd64
nov 29, 2016 10:07:47 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Java Home: C:\Program Files\Java\jre1.8.0_111
nov 29, 2016 10:07:47 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Version: 1.8.0_111-b14
nov 29, 2016 10:07:47 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Vendor: Oracle Corporation
nov 29, 2016 10:07:47 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_BASE: C:\Users\agaragor\workspaceNeon\RBWG\.metadata\.plugins\org.eclipse.wst.server.c ore\tmp1
nov 29, 2016 10:07:47 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_HOME: C:\Users\agaragor\Apache-Tomcat-V8\apache- tomcat-8.0.39
nov 29, 2016 10:07:47 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: - Dcatalina.base=C:\Users\agaragor\workspaceNeon\RBWG\.metadata\.plugins\org.eclip se.wst.server.core\tmp1
nov 29, 2016 10:07:47 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.home=C:\Users\agaragor\Apache- Tomcat-V8\apache-tomcat-8.0.39
nov 29, 2016 10:07:47 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: - Dwtp.deploy=C:\Users\agaragor\workspaceNeon\RBWG\.metadata\.plugins\org.eclipse. wst.server.core\tmp1\wtpwebapps
nov 29, 2016 10:07:47 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Djava.endorsed.dirs=C:\Users\agaragor\Apache- Tomcat-V8\apache-tomcat-8.0.39\endorsed
nov 29, 2016 10:07:47 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dfile.encoding=Cp1252
nov 29, 2016 10:07:47 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: C:\Program Files\Java\jre1.8.0_111\bin;C:\windows\Sun\Java\bin;C:\windows\system32;C:\windo ws;C:/Program Files/Java/jre1.8.0_111/bin/server;C:/Program Files/Java/jre1.8.0_111/bin;C:/Program Files/Java/jre1.8.0_111/lib/amd64;C:\ProgramData\Oracle\Java\javapath;C:\app\aga ragor\product\11.2.0\dbhome_1\bin;C:\windows\system32;C:\windows;C:\windows\Syst em32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Skype\Phone\;C:\Program Files\Java\jdk1.8.0_65\bin;C:\Program Files (x86)\PuTTY\;C:\Users\agaragor\Desktop;;.
nov 29, 2016 10:07:48 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-nio-8080"]
nov 29, 2016 10:07:48 AM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
nov 29, 2016 10:07:48 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-nio-8009"]
nov 29, 2016 10:07:48 AM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
nov 29, 2016 10:07:48 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 1538 ms
nov 29, 2016 10:07:48 AM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
nov 29, 2016 10:07:48 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/8.0.39
nov 29, 2016 10:07:56 AM org.apache.jasper.servlet.TldScanner scanJars
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
nov 29, 2016 10:07:58 AM org.apache.jasper.servlet.TldScanner scanJars
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
nov 29, 2016 10:07:58 AM org.apache.catalina.core.ApplicationContext log
INFO: No Spring WebApplicationInitializer types detected on classpath
nov 29, 2016 10:07:59 AM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'dispatcher'
nov 29, 2016 10:07:59 AM org.springframework.web.servlet.DispatcherServlet initServletBean
INFO: FrameworkServlet 'dispatcher': initialization started
nov 29, 2016 10:07:59 AM org.springframework.web.context.support.XmlWebApplicationContext prepareRefresh
INFO: Refreshing WebApplicationContext for namespace 'dispatcher-servlet': startup date [Tue Nov 29 10:07:59 BRST 2016]; root of context hierarchy
nov 29, 2016 10:07:59 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource [/WEB- INF/todo-servlet.xml]
nov 29, 2016 10:08:02 AM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMappi ng register
INFO: Mapped "{[/login]}" onto public java.lang.String com.ezmsip.controller.LoginController.sayHello()
nov 29, 2016 10:08:02 AM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapt er initControllerAdviceCache
INFO: Looking for @ControllerAdvice: WebApplicationContext for namespace 'dispatcher-servlet': startup date [Tue Nov 29 10:07:59 BRST 2016]; root of context hierarchy
nov 29, 2016 10:08:02 AM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapt er initControllerAdviceCache
INFO: Looking for @ControllerAdvice: WebApplicationContext for namespace 'dispatcher-servlet': startup date [Tue Nov 29 10:07:59 BRST 2016]; root of context hierarchy
nov 29, 2016 10:08:02 AM org.springframework.web.servlet.DispatcherServlet initServletBean
INFO: FrameworkServlet 'dispatcher': initialization completed in 3226 ms
nov 29, 2016 10:08:02 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-8080"]
nov 29, 2016 10:08:02 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-nio-8009"]
nov 29, 2016 10:08:02 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 14164 ms
更改web.xml
,如下所示:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/todo-servlet.xml</param-value>
</context-param>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value></param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/your-mapping/*</url-pattern>
</servlet-mapping>
<listener>
<listenerclass>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
我刚刚在spring tool suit中创建了一个示例spring mvc项目(没有进行任何修改),当我执行它时,我将按照index.jsp获得输出。但在此之后,我只在view文件夹中添加一个index.html页面,并进行了以下两个更改 > 在控制器类i中添加:返回“index”; 在Pivotal Server Developer Edition V3.1上执行更改后的代码时,我得到HTTP
我试图在Eclipse中制作一个spring hello world程序。这是代码 index.jsp HelloWorldController.java 当我使用像http://localhost:8080/springmvcbasic/hello这样的url时,我得到的是 我已经从这里拿走了代码
如何在SpringMVC中实现自定义http错误处理。 例如:我有一个urlhttp://localhost:8080/demo/canvas 它显示我的画布页面,但如果用户错过了网址并键入http://localhost:8080/demo/canva 它显示了Tomcat呈现的HTTP状态404。我希望它是自定义jsp页面。
web.xml pom.xml homeController.java } home.jsp
HTTP Status 404-/controller/results.jsp类型状态报告消息/controller/results.jsp描述请求的资源(/controller/results.jsp)不可用。Apache Tomcat/7.0.12 我的web.xml代码: servlet-context.xml 谢了。
为什么我在web-inf/view//admin得到双斜线。我是Java MVC的新手,所以请给我任何建议,我做错了什么? 这是我的代码` 控制器-