你好我是MVC Spring的新手。我使用Spring创建了简单的应用程序。我使用etbeans 7.3.1 Ide,我使用Spring版本2.5.6。当我尝试运行我的应用程序时,它给我一个错误,如调度程序抛出异常。我为我的应用程序创建了以下类。 HelloController.java和Name1.java,如下所示。
package controller;
import java.net.BindException;
import java.util.jar.Attributes.Name;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;
import service.HelloService;
import controller.Name1;
public class HelloController extends SimpleFormController {
private HelloService helloService;
public HelloController()
{
setCommandClass(Name.class);
setCommandName("name");
setSuccessView("helloView");
setFormView("nameView");
}
protected ModelAndView onSubmit(HttpServletRequest
request,HttpServletResponse response,Object
command,BindException errors) throws Exception {
Name1 name = (Name1) command;
ModelAndView mv = new ModelAndView(getSuccessView());
mv.addObject("helloMessage", helloService.sayHello(name.getValue()));
return mv;
}
}
现在我正在展示Name1.java
package controller;
public class Name1
{
private String value;
public String getValue()
{
return value;
}
public void setValue(String value)
{
this.value = value;
}
}
HelloService.java
package service;
import controller.Name1;
public class HelloService
{
public static String sayHello(String name)
{
return "Hello " + name + "!";
}
}
现在我是Show dispatcher-servlet.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:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-
beans-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema
/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema
/tx/spring-tx-2.5.xsd">
<bean
class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/>
<bean class="controller.HelloController" p:helloService-ref="helloService"/>
<bean id="urlMapping"
class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="hello.htm">indexController</prop>
</props>
</property>
</bean>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/"
p:suffix=".jsp" />
<bean name="indexController"
class="org.springframework.web.servlet.mvc.ParameterizableViewController"
p:viewName="hello" />
</beans>
现在我向您展示我的2个jsp文件,该文件在下面给出
Helloview.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Hello</title>
</head>
<body>
<h1>${helloMessage}</h1>
</body>
</html>
nameView.JSP中
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Name View</title>
</head>
<body>
<spring:nestedPath path="name">
<form action="" method="post">
Name:
<spring:bind path="value">
<input type="text" name="${status.expression}" value="${status.value}">
</spring:bind>
<input type="submit" value="OK">
</form>
</spring:nestedPath>
</body>
</html>
我的踪迹在下面给出。 类型异常报告
message Servlet.init() for servlet dispatcher threw exception
description The server encountered an internal error that prevented it from
fulfilling this
request.
exception
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:936)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
org.apache.coyote.http11.AbstractHttp11Processor.process
(AbstractHttp11Processor.java:1004)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process
(AbstractProtocol.java:589)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
java.lang.Thread.run(Thread.java:724)
我也改变了项目的属性。从右键单击项目然后属性 - >运行 - &gt; RelaticURL = hello.htm然后我运行我的项目我得到了我在标题中提到的错误。所以请帮助我......我犯了错误。 谢谢。