2016-12-06 6 views
0

Erreur 500Erreur de création de forme à l'aide de ressort balise forme de ressort

JDK 1,8

Tomcat 8.0.38

état HTTP 500 - Une exception est survenue traitement page JSP /index1.jsp à la ligne 11

type de rapport d'exception

un message Une exception est survenue le traitement page JSP/en dex1.jsp à la ligne 11

description Le serveur a rencontré une erreur interne qui l'a empêché de répondre à cette demande.

exception 

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

8: <title>Index 2</title> 
9: </head> 
10: <body> 
11:  <form:form action="user_profile" method="post" commandName="abc"> 
12:   <form:label path="userID">Username</form:label> 
13:   <form:input path="userID" /> 
14: 


Stacktrace: 
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:579) 
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:471) 
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396) 
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340) 
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729) 
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) 

root cause 

java.lang.IllegalStateException: No WebApplicationContext found: no ContextLoaderListener registered? 
    org.springframework.web.context.support.WebApplicationContextUtils.getRequiredWebApplicationContext(WebApplicationContextUtils.java:90) 
    org.springframework.web.servlet.support.RequestContextUtils.getWebApplicationContext(RequestContextUtils.java:85) 
    org.springframework.web.servlet.support.RequestContext.initContext(RequestContext.java:209) 
    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.index1_jsp._jspx_meth_form_005fform_005f0(index1_jsp.java:179) 
    org.apache.jsp.index1_jsp._jspService(index1_jsp.java:135) 
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) 
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729) 
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:438) 
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396) 
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340) 
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729) 
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) 

index1.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" 
    pageEncoding="ISO-8859-1"%> 
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="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=ISO-8859-1"> 
<title>Index 2</title> 
</head> 
<body> 
<form:form action="user_profile" method="post" commandName="abc"> 
    <form:label path="userID">Username</form:label> 
    <form:input path="userID" /> 


    <form:label path="firstName">First Name</form:label> 
    <form:input path="firstName" /> 

    <form:label path="lastName">Last Name</form:label> 
    <form:input path="lastName" /> 

    <form:label path="dateOfBirth">Date Of Birth</form:label> 
    <form:input path="dateOfBirth" /> 


    <form:label path="gender">Gender</form:label> 
    <form:input path="gender" /> 

    <form:label path="street">Street</form:label> 
    <form:input path="street" /> 

    <form:label path="location">Location</form:label> 
    <form:input path="location" /> 


    <form:label path="city">City</form:label> 
    <form:input path="city" /> 

    <form:label path="state">State</form:label> 
    <form:input path="state" /> 

    <form:label path="pincode">Pincode</form:label> 
    <form:input path="pincode" /> 

    <form:label path="mobileNo">EmailID</form:label> 
    <form:input path="mobileNo" /> 

    <form:label path="password">Password</form:label> 
    <form:input path="password" /> 
    <input type="submit" value="clickMe"> 

</form:form> 

</body> 
</html> 

com.happiestminds.ocs.bean.ProfileBean.java

package com.happiestminds.ocs.bean; 

import java.util.Date; 

import javax.persistence.Column; 
import javax.persistence.Entity; 
import javax.persistence.Id; 
import javax.persistence.Table; 

@Entity 
@Table(name = "OCS_TBL_USER_PROFILE") 
public class ProfileBean { 

    public ProfileBean(){ 

    } 
    @Id 
    @Column(name = "USERID") 
    private String userID; 

    @Column(name = "FIRSTNAME") 
    private String firstName; 

    @Column(name = "LASTNAME") 
    private String lastName; 

    @Column(name = "DATEOFBIRTH") 
    private Date dateOfBirth; 

    @Column(name = "GENDER") 
    private String gender; 

    @Column(name = "STREET") 
    private String street; 

    @Column(name = "LOCATION") 
    private String location; 

    @Column(name = "CITY") 
    private String city; 

    @Column(name = "STATE") 
    private String state; 

    @Column(name = "PINCODE") 
    private String pincode; 

    @Column(name = "MOBILENO") 
    private String mobileNo; 

    @Column(name = "EMAILID") 
    private String emailID; 

    @Column(name = "PASSWORD") 
    private String password; 

    public String getUserID() { 
     return userID; 
    } 

    public void setUserID(String userID) { 
     this.userID = userID; 
    } 

    public String getFirstName() { 
     return firstName; 
    } 

    public void setFirstName(String firstName) { 
     this.firstName = firstName; 
    } 

    public String getLastName() { 
     return lastName; 
    } 

    public void setLastName(String lastName) { 
     this.lastName = lastName; 
    } 

    public Date getDateOfBirth() { 
     return dateOfBirth; 
    } 

    public void setDateOfBirth(Date dateOfBirth) { 
     this.dateOfBirth = dateOfBirth; 
    } 

    public String getGender() { 
     return gender; 
    } 

    public void setGender(String gender) { 
     this.gender = gender; 
    } 

    public String getStreet() { 
     return street; 
    } 

    public void setStreet(String street) { 
     this.street = street; 
    } 

    public String getLocation() { 
     return location; 
    } 

    public void setLocation(String location) { 
     this.location = location; 
    } 

    public String getCity() { 
     return city; 
    } 

    public void setCity(String city) { 
     this.city = city; 
    } 

    public String getState() { 
     return state; 
    } 

    public void setState(String state) { 
     this.state = state; 
    } 

    public String getPincode() { 
     return pincode; 
    } 

    public void setPincode(String pincode) { 
     this.pincode = pincode; 
    } 

    public String getMobileNo() { 
     return mobileNo; 
    } 

    public void setMobileNo(String mobileNo) { 
     this.mobileNo = mobileNo; 
    } 

    public String getEmailID() { 
     return emailID; 
    } 

    public void setEmailID(String emailID) { 
     this.emailID = emailID; 
    } 

    public String getPassword() { 
     return password; 
    } 

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

} 

RegisterAndLoginController.java

/** 
* 
*/ 
package com.happiestminds.ocs.controller; 

import java.util.Date; 

import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.stereotype.Controller; 
import org.springframework.ui.Model; 
import org.springframework.ui.ModelMap; 
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 org.springframework.web.servlet.ModelAndView; 

import com.happiestminds.ocs.bean.ProfileBean; 
import com.happiestminds.ocs.service.PatientService; 

/** 
* @author Ankush 
* 
*/ 
@Controller 
public class RegisterAndLoginController { 

    /*@Autowired 
    private AdministratorService administratorService;*/ 

    @Autowired 
    private PatientService patientService; 

    /*@Autowired 
    private ReporterService reporterService;*/ 

    //Autowiring ends here 

    @RequestMapping(value = "user_profile",method= RequestMethod.POST) 
    public ModelAndView registerUser(@ModelAttribute("abc") ProfileBean pf){ 

     System.out.println(pf.getUserID()); 
     System.out.println(pf.getFirstName()); 


     return new ModelAndView("test"); 
    } 

} 

web.xml

<?xml version="1.0" encoding="UTF-8"?> 
<web-app version="2.5" 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"> 

    <servlet> 
     <servlet-name>clinic</servlet-name> 
     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
     <init-param> 
      <param-name>contextConfigLocation</param-name> 
      <param-value>/WEB-INF/ocs/clinic-servlet.xml</param-value> 
     </init-param> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 

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

    <welcome-file-list> 
     <welcome-file>index1.jsp</welcome-file> 
    </welcome-file-list> 

</web-app> 

WEB-INF/ocs/clinique servlet.xml

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
     xmlns:mvc="http://www.springframework.org/schema/mvc" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:tx="http://www.springframework.org/schema/tx" 
    xsi:schemaLocation=" 
http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd 
http://www.springframework.org/schema/mvc 
http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd 
http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context-3.2.xsd 
http://www.springframework.org/schema/tx 
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd"> 

    <context:property-placeholder location="classpath:resources/database.properties" /> 
    <context:component-scan base-package="com.happiestminds.ocs" /> 

    <mvc:annotation-driven /> 
    <mvc:resources mapping="/resources/**" location="/resources/" /> 

    <tx:annotation-driven transaction-manager="hibernateTransactionManager" /> 

    <bean id="jspViewResolver" 
     class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
     <property name="viewClass" 
      value="org.springframework.web.servlet.view.JstlView" /> 
     <property name="prefix" value="/WEB-INF/clinicViews/" /> 
     <property name="suffix" value=".jsp" /> 
    </bean> 

    <bean id="dataSource" 
     class="org.springframework.jdbc.datasource.DriverManagerDataSource"> 
     <property name="driverClassName" value="${database.driver}" /> 
     <property name="url" value="${database.url}" /> 
     <property name="username" value="${database.user}" /> 
     <property name="password" value="${database.password}" /> 
    </bean> 

    <bean id="sessionFactory" 
     class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> 
     <property name="dataSource" ref="dataSource" /> 
     <property name="annotatedClasses"> 
      <list> 
       <value>com.happiestminds.ocs.bean.ProfileBean</value> 
      </list> 
     </property> 
     <property name="hibernateProperties"> 
      <props> 
       <prop key="hibernate.dialect">${hibernate.dialect}</prop> 
       <prop key="hibernate.show_sql">${hibernate.show_sql}</prop> 
       <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop> 
      </props> 
     </property> 
    </bean> 

    <bean id="hibernateTransactionManager" 
     class="org.springframework.orm.hibernate3.HibernateTransactionManager"> 
     <property name="sessionFactory" ref="sessionFactory" /> 
    </bean> 
</beans> 

Répondre

1

Lisez vos journaux d'erreurs

java.lang .IllegalStateException: Non WebApplicationContext trouvé: non ContextLoaderListener enregistré ?

Vous devez ajouter web.xml

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

si j'ajouter que je reçois une autre erreur ** analyse syntaxique de document XML à partir des ressources ServletContext [/WEB-INF/applicationContext.xml]; l'exception imbriquée est java.io.FileNotFoundException: Impossible d'ouvrir la ressource ServletContext [/WEB-INF/applicationContext.xml] \t at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions (XmlBeanDefinitionReader.java:341) ** –

+0

passez en revue votre source de code dans la recherche de applicationContext.xml à un chemin incorrect. essayez cette solution http://stackoverflow.com/questions/22350721/could-not-open-servletcontext-resource-web-inf-applicationcontext-xml et assurez-vous que vous avez indiqué le bon chemin vers votre fichier de configuration. – GVArt

+0

Je l'ai eu mais je place mon ** ContextLoaderListener ** dans la balise param dans ** web.xml ** alors ça devrait être ok et il ne devrait pas me demander d'inclure une balise d'écoute selon le lien que vous m'avez suggéré. Merci mais ça n'aide pas ... –