2016-03-23 11 views
1

のweb.xml `スプリングMVC形態<form:form > org.apache.jasper.JasperExceptionが:例外処理JSPページを発生

<?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" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
    http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> 
     <display-name>SpringMVCLoginFormValidate</display-name> 
     <welcome-file-list> 
     <welcome-file>LoginForm.jsp</welcome-file> 
     </welcome-file-list> 

     <servlet> 
     <servlet-name>spring</servlet-name> 
     <servlet-class> 
      org.springframework.web.servlet.DispatcherServlet 
     </servlet-class> 
     <load-on-startup>1</load-on-startup> 
     </servlet> 

    <servlet-mapping> 
     <servlet-name>spring</servlet-name> 
     <url-pattern>/</url-pattern> 
    </servlet-mapping> 

    </web-app>` 

ばね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:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd"> <mvc:annotation-driven /> <context:component-scan base-package="com.hr.controller" /> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/" /> <property name="suffix" value=".jsp" /> </bean> <bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource"> <property name="basename" value="/WEB-INF/messages" /> </bean> </beans> 

`

`

LoginForm.jsp LoginController.java

package com.hr.controller; 


import java.util.Map; 

import org.springframework.stereotype.Controller; 
import org.springframework.validation.BindingResult; 
import org.springframework.web.bind.annotation.ModelAttribute; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.RequestMethod; 

import com.hr.model.User; 


@Controller 
public class LoginController { 
    @RequestMapping(value = "/login", method = RequestMethod.GET) 
    public String viewLogin(Map<String, Object> model) { 
     User user = new User(); 
     model.put("userForm", user); 
     return "LoginForm"; 
    } 

    @RequestMapping(value = "/login", method = RequestMethod.POST) 
    public String doLogin(@ModelAttribute("userForm") User userForm, 
      BindingResult result, Map<String, Object> model) { 

     if (result.hasErrors()) { 
      return "LoginForm"; 
     } 

     return "LoginSuccess"; 
    } 
} 

LoginSuccess.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8" 
    pageEncoding="UTF-8"%> 
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
    "http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
<title>Welcome</title> 
</head> 
<body> 
    <div align="center"> 
     <h2>Welcome ${userForm.email}! You have logged in successfully.</h2> 
    </div> 
</body> 
</html> 

User.java

`

<%@ page language="java" contentType="text/html; charset=UTF-8" 
    pageEncoding="UTF-8"%> 
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%> 

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
    "http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
<title>Login</title> 
<style> 
    .error { 
     color: red; font-weight: bold; 
    } 
</style> 
</head> 
<body> 
    <div align="center"> 
     <h2>Spring MVC Form Validation Demo - Login Form</h2> 
     <table border="0" width="90%"> 
     <form:form action="login" commandName="userForm" method="post"> 
       <tr> 
        <td align="left" width="20%">Email: </td> 
        <td align="left" width="40%"><form:input path="email" size="30"/></td> 
        <td align="left"><form:errors path="email" cssClass="error"/></td> 
       </tr> 
       <tr> 
        <td>Password: </td> 
        <td><form:password path="password" size="30"/></td> 
        <td><form:errors path="password" cssClass="error"/></td> 
       </tr> 
       <tr> 
        <td></td> 
        <td align="center"><input type="submit" value="Login"/></td> 
        <td></td> 
       </tr> 
     </form:form> 
     </table> 
    </div> 
</body> 
</html> 

` 

enter image description here

としてデバッグ中

package com.hr.model; 

import org.hibernate.validator.Email; 
import org.hibernate.validator.NotEmpty; 
import org.hibernate.validator.Size; 


public class User { 
    @NotEmpty 
    @Email 
    private String email; 

    @NotEmpty(message = "Please enter your password.") 
    @Size(min = 6, max = 15, message = "Your password must between 6 and 15 characters") 
    private String password; 

    public String getEmail() { 
     return email; 
    } 

    public void setEmail(String email) { 
     this.email = email; 
    } 

    public String getPassword() { 
     return password; 
    } 

    public void setPassword(String password) { 
     this.password = password; 
    } 
} 

は、私は春4.2.5のすべてのjarファイルを追加し、エラーを解決する方法を瓶

を休止していたエラーを取得しています?

HTTP Status 500 - An exception occurred processing JSP page /LoginForm.jsp at line 21 

type Exception report 

message An exception occurred processing JSP page /LoginForm.jsp at line 21 

description The server encountered an internal error that prevented it from fulfilling this request. 

exception 

org.apache.jasper.JasperException: An exception occurred processing JSP page /LoginForm.jsp at line 21 

18:  <div align="center"> 
19:   <h2>Spring MVC Form Validation Demo - Login Form</h2> 
20:   <table border="0" width="90%"> 
21:   <form:form action="login" commandName="userForm" method="post"> 
22:     <tr> 
23:      <td align="left" width="20%">Email: </td> 
24:      <td align="left" width="40%"><form:input path="email" size="30"/></td> 


Stacktrace: 
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568) 
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:465) 
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390) 
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334) 
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728) 

root cause 

java.lang.IllegalStateException: No WebApplicationContext found: not in a DispatcherServlet request and no ContextLoaderListener registered? 
    org.springframework.web.servlet.support.RequestContext.initContext(RequestContext.java:235) 
    org.springframework.web.servlet.support.JspAwareRequestContext.initContext(JspAwareRequestContext.java:74) 
    org.springframework.web.servlet.support.JspAwareRequestContext.<init>(JspAwareRequestContext.java:48) 
    org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:77) 
    org.apache.jsp.LoginForm_jsp._jspService(LoginForm_jsp.java:107) 
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) 
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728) 
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432) 
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390) 
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334) 
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728) 

note The full stack trace of the root cause is available in the Apache Tomcat/7.0.37 logs. 
Apache Tomcat/7.0.37 

答えて

0

要求が豆をロードするためにDeployment descriptorのweb.xmlになった後、我々は以下に定義するweb.xmlにリスナーとして定義するContextLoaderListenerを必要としています。これに

<listener> 
    <listener-class> 
     org.springframework.web.context.ContextLoaderListener 
    </listener-class> 
</listener> 

我々は今、そのは私にorg.apache.jasper.JasperExceptionがなどのエラーを示すスプリングBeanファイルの場所に

<context-param> 
    <param-name>contextConfigLocation</param-name> 
    <param-value> 
     /WEB-INF/spring-servlet.xml 
    </param-value> 
</context-param> 
+0

をコンテキストのparamポインティングを追加する必要があります。例外は、/処理JSPページを発生しましたLoginForm.jspライン12 9で: 10:

11: 12:​​名前 13:​​<フォーム:入力パス= "FIRSTNAME" /> 14: 15: – HARISH

+0

問題の初期誤差のために、あなたはリスナーを配置する必要があります。あなたが質問に投稿したログインjspのファーストネームは表示されません。エラーが異なる場合は、別の質問をしてください – VinayVeluri

関連する問題