2016-03-23 2 views
1

web.xml `Feder mvc Form <form:form > org.apache.jasper.JasperException: eine Ausnahme aufgetreten Verarbeitung JSP-Seite

<?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>` 

feder 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

`

<%@ 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> 

` 

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

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; 
    } 
} 

bin immer den Fehler beim Debuggen als

enter image description here

ich alle JAR-Dateien der Feder 4.2.5 hinzugefügt hatte und Hibernate Gläser

, wie der Fehler lösen ??? wie unten definiert

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 

Antwort

0

Nachdem die Anforderung erreicht den Deployment descriptor web.xml, die Bohnen zu laden, müssen wir ContextLoaderListener in der web.xml als Zuhörer definiert werden.

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

Dazu wir einen Kontext param zeigt auf die Feder Bean Dateipfad

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

jetzt als org.apache.jasper.JasperException seine zeigt mir Fehler hinzufügen müssen: Eine Ausnahme ist aufgetreten Verarbeitung JSP-Seite/LoginForm.jsp in Zeile 12 9: 10:

11: 12: 13: 14: 15: – HARISH

+0

Für den ersten Fehler in Frage, müssen Sie den Hörer platzieren. Ich sehe keinen Vornamen in der Login-JSP, die Sie in der Frage gepostet haben. Wenn der Fehler anders ist, bitte eine weitere Frage stellen – VinayVeluri

Verwandte Themen
Vorname