当前位置: 首页 > 知识库问答 >
问题:

使用Spring表单标签在Spring中创建表单时出错

洪弘亮
2023-03-14

错误500

JDK 1.8

Tomcat 8.0.38

HTTP状态500-处理JSP页面/index1时发生异常。11号线

类型异常报告

消息处理JSP页面/index1时发生异常。11号线

说明服务器遇到内部错误,无法满足此请求。

    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>

通用域名格式。快乐的心情。业主立案法团。豆小豆。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-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>

共有1个答案

拓拔骁
2023-03-14

读取错误日志

java.lang.IllegalState异常:未找到WebApplication Context:未注册ContextLoaderListener?

你必须加入网络。xml

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
 类似资料:
  • 14.9. 使用Spring的表单标签库 从2.0开始,Spring提供全面的,支持数据绑定的JSP标签来处理表单元素(如果你使用JSP和Spring的Web MVC框架的话)。 每个标签所支持的属性跟其对应的HTML标签相同,这样这些标签看起来就不陌生,而且很容易用。 由这些标签库生成的HTML页面符合HTML 4.01/XHTML 1.0标准。 与其它的标签库不同,Spring的表单标签库和S

  • 我不熟悉Thymeleaf,我对使用表单动态创建URL有一个问题。 我有一个简单的spring boot应用程序,它将对象存储在数据库中,我可以使用简单的URL查询数据库。例如,url/distance/0.3将返回距离属性小于或等于0.3的对象。当我在浏览器中编辑这些URL时,它们可以完美地工作。 我希望用户能够自己设置这些搜索值。我试图创建一个简单的表单,用用户输入创建上面的url,但出现以下

  • 得到错误"表客户已经存在"当我试图创建一个表在H2内存数据库使用schema.sql.我使用的是Spring启动版本:2.5.4和以下是我的pom.xml.它的工作正常,如果我使用Spring启动版本:2.4.3 这是我的代码: 当我启动应用程序时,我收到以下错误。如何强制H2使用schema.sql创建表格? 原因:io。r2dbc。spi。R2dbcBadGrammarException:表“

  • 主要内容:简单UI标签:,组 UI 标签:,选择 UI 标签:form 标签的列表是Struts的UI标签的一个子集。这些标签可以帮助渲染中需要Struts Web应用程序和用户界面可以分为三类。本章将带你通过所有三种类型的UI标签: 简单UI标签: 我们已经使用这些标签已经在我们的例子中。让我们来看看一个简单的一些简单UI标签的视图页面email.jsp: 如果你是知道的HTML,那么所有使用的标签是很常见的HTML标签与一个额外前缀s:随着每个标签和不同

  • 问题内容: 我想为form.ModelChoiceField创建动态标签,我想知道如何做到这一点。我有以下表单类: 默认标签由Profile定义中指定的unicode函数定义。但是,需要动态创建由ModelChoiceField创建的单选按钮的标签。 首先,我认为我可以按照Django文档中的描述简单地覆盖ModelChoiceField。但这会创建静态标签。它允许你定义任何标签,但是一旦做出选择

  • 基于活动记录(ActiveRecord)的表单:ActiveForm 在yii中使用表单的主要方式是通过 yii\widgets\ActiveForm。 当某个表单是基于一个模型时,应该首选这种方式。 此外,在 yii\helpers\Html 中有很多实用的方法为表单添加按钮和帮助文档。 在客户端显示的表单,大多数情况下都有一个相应的模型, 用来在服务器上验证其输入的数据(可在输入验证一节获取关