Wednesday, 28 August 2013

dispatcher throw Exception in Spring application

dispatcher throw Exception in Spring application

Hello I am New in new in MVC Spring.I have Create Simple Application using
Spring. i use etbeans 7.3.1 Ide,i use Spring version 2.5.6.when i try to
run my application it gives me error like dispatcher throw Exception . i
have create following class for my application. HelloController.java and
Name1.java which is given below.
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;
}
}
Now I am Showing 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 + "!";
}
}
Now I am Show dispatcher-servlet.xml file.
<?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>
Now I am showing you my 2 jsp file which is given below
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>
My Trace is Given Below. type Exception report
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)
and i have also change property of project. from right click on project
then property->run->RelaticURL=hello.htm then I run My project I got The
Error which i mention in Title. So Kindly Help Me.. Where I made Mistake.
Thank you.

No comments:

Post a Comment