Spring 弹簧配置
我试图运行一个示例Spring应用程序,但配置失败。我搜索了我的问题,但我觉得一切都很好 Web.xmlSpring 弹簧配置,spring,configuration,Spring,Configuration,我试图运行一个示例Spring应用程序,但配置失败。我搜索了我的问题,但我觉得一切都很好 Web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/n
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>Spring Hello World</display-name>
<welcome-file-list>
<welcome-file>/</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>springDispatcher</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springDispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
spring-context.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: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-3.0.xsd
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">
<context:component-scan base-package="com.fyp.ptma.controller" />
<mvc:annotation-driven />
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
WEB-INF/views/hello.jsp中的hello.jsp
<html>
<head>
<title>Home</title>
</head>
<body>
<h1>Hello World!</h1>
<hr/>
<form action="hi">
Name: <input type="text" name="name"> <input type="submit" value="Submit">
</form>
</body>
</html>
家
你好,世界!
姓名:
tomcat中的ptma.xml文件,位于conf/Catalina/localhost/ptma.xml
<?xml version="1.0" encoding="utf-8"?>
<Context docBase="/Volumes/DataDrive/FYP/TestMonkeyAppWeb/WebContent" debug="0" crossContext="true" reloadable="true" >
</Context>
我以localhost:8080/ptma的身份访问我的项目/
但是它说HTTP状态404和tomcat日志似乎工作正常。web.xml中的欢迎文件映射似乎不正确。将其更改为index.jsp,在应用程序的根目录中创建一个同名文件,并重定向到First控制器。您的表单中没有方法属性。表单属性与某些事情有关提交表单时,我的问题是我的页面甚至无法打开我的webcontent/index.jsp上有index.jsp文件,但是当我浏览localhost:8080/ptma/hello时,webcontent/WEB-INF/hello.jsp中的文件不会打开。它显示HTTP状态404是的,您已将jsp视图映射到“/WEB-INF/views/”中,因此它们需要存储在该目录中。在tomcat日志中,它打印出未找到URI为[/ptma/hello]的HTTP请求的映射在名为“springDispatcher”的DispatcherServlet中,您是否可以检查控制器是否在启动时通过注释扫描检测到?这就是我如何检测它的问题?
<?xml version="1.0" encoding="utf-8"?>
<Context docBase="/Volumes/DataDrive/FYP/TestMonkeyAppWeb/WebContent" debug="0" crossContext="true" reloadable="true" >
</Context>