当我尝试运行这个简单的html表单时:
<html>
<head>
<title>Enter a new Page</title>
</head>
<body>
<div id="editPresPage">
<form action="editPresPage.do" method="post">
<label>Enter Page ID</label><input type="text" name="page_id"/>
<label>Enter Header1</label><input type="text" name="h1"/>
<label>Enter Header2</label><input type="text" name="h2"/>
<label>Enter Header3</label><input type="text" name="h3"/>
<label>Enter Header4</label><input type="text" name="h4"/>
<label>Enter Page Text</label><input type="text" name="page_text"/>
<input type="submit" value="Add New Page"/>
</form>
</div>
</body>
</html>
我收到错误HTTP Status 500 - servlet的Servlet.init()Dispatcher在我的浏览器中引发了异常。
在我的命令行窗口(当我运行tomcat的start.batch文件时打开) 我收到以下错误:
log4j:WARN找不到appender 记录器(org.springframework.web.servlet.dispatcherservlet)
My Dispatcher-servlet.xml文件:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
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">
<import resource="/application.xml"/>
<bean name="/editPresPage.do"
class="my.pack.webTier.control.EditPresPageController" >
<property name="page_manager_service" ref="page_manager_service"/>
</bean>
<!-- I also tried using with annotations -->
<!-- <context:component-scan base-package="my.pack"/> -->
</beans>
我的web.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<web-app 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_2_5.xsd"
version="2.5">
<servlet>
<servlet-name>Dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Dispatcher</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<!-- Tomcat configuration -->
<Context path="/myWebApp" docBase="../tomcat\work\Catalina\localhost\mywebapptomcat\work\Catalina\localhost\mywebapp">
<Loader
loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader"/>
</Context>
</web-app>
那就是我的控制器:
package my.pack.webTier.control;
import my.pack.dataAccessTier.domain.Presentation_page;
import my.pack.serviceTier.services.Page_manager_service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
//@Controller
public class EditPresPageController {
//@Autowired
private Page_manager_service page_manager_service;
public void setPage_manager_service(Page_manager_service page_manager_service) {
this.page_manager_service = page_manager_service;
}
@RequestMapping("/editPresPage")
public ModelAndView EditPresPage(@RequestParam("page_id") int page_id,
@RequestParam("h1") String h1_value,
@RequestParam("h2") String h2_value,
@RequestParam("h3") String h3_value,
@RequestParam("h4") String h4_value,
@RequestParam("page_text") String page_text)
{
Presentation_page new_page=new Presentation_page(page_id,h1_value,h2_value,
h3_value,h4_value,page_text);
page_manager_service.create_new_page(new_page);
return new ModelAndView("/thanks.html");
}
}
stacktrace异常:
javax.servlet.ServletException: Servlet.init() for servlet Dispatcher threw exception
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
java.lang.Thread.run(Thread.java:722)
我正在使用spring MVC 3.2,eclipse 3.7,springTomcat / 7.0.30并在我的项目中使用ANT。
我已经搜索了这个要求的答案 - 并没有找到答案。
答案 0 :(得分:7)
您将调度员映射到* .do:
<servlet-mapping>
<servlet-name>Dispatcher</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
但你的控制器是在没有.do:
的网址上映射的@RequestMapping("/editPresPage")
尝试将其更改为:
@RequestMapping("/editPresPage.do")
答案 1 :(得分:-2)
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>teste4</groupId>
<artifactId>teste4</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<repositories>
<repository>
<id>prime-repo</id>
<name>PrimeFaces Maven Repository</name>
<url>http://repository.primefaces.org</url>
<layout>default</layout>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.2.4</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.2.4</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>4.0</version>
</dependency>
<dependency>
<groupId>org.primefaces.themes</groupId>
<artifactId>bootstrap</artifactId>
<version>1.0.9</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.27</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.2.7.Final</version>
</dependency>
</dependencies>
</project>