Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用Spring提交表单_Java_Xml_Spring_Forms_Spring Mvc - Fatal编程技术网

Java 使用Spring提交表单

Java 使用Spring提交表单,java,xml,spring,forms,spring-mvc,Java,Xml,Spring,Forms,Spring Mvc,我是一个和春天一起工作的傻瓜 我正在尝试提交表单,但出现以下错误: ERROR: org.springframework.web.servlet.tags.form.InputTag - Neither BindingResult nor plain target object for bean name 'hitoForm' available as request attribute 表格如下: <form:form role="form" action="modifyHito" m

我是一个和春天一起工作的傻瓜

我正在尝试提交表单,但出现以下错误:

ERROR: org.springframework.web.servlet.tags.form.InputTag - Neither BindingResult nor plain target object for bean name 'hitoForm' available as request attribute
表格如下:

<form:form role="form" action="modifyHito" method="post" commandName="hitoForm">
      <div class="form-group">
          <label>Hito number</label>
          <form:input class="form-control" path="hitoNumber" disabled="" type="text"/>
      </div>
      <div class="form-group">
          <label>Title</label>
          <form:input class="form-control" path="title" type="text" maxlength="50"/>
      </div>
      <div class="form-group">
          <label>Subtitle</label>
          <form:input class="form-control" path="subtitle" type="text" maxlength="200"/>
       </div>
       <div class="form-group">
          <label>Date</label>
          <form:input class="form-control" path="date" type="text" maxlength="50"/>
       </div>
       <div class="form-group">
          <label>Latitude</label>
          <form:input class="form-control" path="latitude" type="text" maxlength="15"/>
       </div>
       <div class="form-group">
          <label>Longitude</label>
          <form:input class="form-control" path="longitude" type="text" maxlength="15"/>
        </div>
</form:form>
我的代码出了什么问题?我试过好几种方法,但我总是犯同样的错误。 提前谢谢

编辑

这是我的实体Hito:

@Entity
@Table(name="hito")
public class Hito implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @Column(name = "id")
    @GeneratedValue(strategy = GenerationType.AUTO)
    private int id;
    private int hitoNumber;
    private String title;
    private String subtitle;
    private String date;
    private double latitude;
    private double longitude;

    public Integer getId()
    {
        return id;
    }

    public void setId(Integer id)
    {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getSubtitle() {
        return subtitle;
    }

    public void setSubtitle(String subtitle) {
        this.subtitle = subtitle;
    }

    public String getDate() {
        return date;
    }

    public void setDate(String date) {
        this.date = date;
    }

    public double getLatitude() {
        return latitude;
    }

    public void setLatitude(double latitude) {
        this.latitude = latitude;
    }

    public double getLongitude() {
        return longitude;
    }

    public void setLongitude(double longitude) {
        this.longitude = longitude;
    }

    public Integer getHitoNumber() {
        return hitoNumber;
    }

    public void setHitoNumber(Integer hitoNumber) {
        this.hitoNumber = hitoNumber;
    }
}
和web.xml:

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/spring/applicationContext.xml</param-value>
  </context-param>

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

  <display-name>PintiaServer</display-name>

  <servlet>
    <servlet-name>pintiaserver</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>/WEB-INF/spring/app-config.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet-mapping>
    <servlet-name>pintiaserver</servlet-name>
    <url-pattern>*.htm</url-pattern>
    <url-pattern>/pintiaserver/*</url-pattern>
  </servlet-mapping>

</web-app>

上下文配置位置
/WEB-INF/spring/applicationContext.xml
org.springframework.web.context.ContextLoaderListener
PintiaServer
pintiaserver
org.springframework.web.servlet.DispatcherServlet
上下文配置位置
/WEB-INF/spring/app-config.xml
1.
pintiaserver
*.htm
/pintiaserver/*

我想您使用的是其他的
型号。class
。应该使用
org.springframework.ui.Model
并使用
Model.addAttribute
而不是
Model.put

出现上述错误是因为Spring找不到要与表单数据绑定的ModelAttribute

试试这个:

@RequestMapping(method = RequestMethod.GET) 
    public String viewModificationForm(Model model) {
        Hito hitoForm = new Hito();
        model.addAttribute("hitoForm", hitoForm);
        return "main"; 
    } 

我想您正在使用其他的
模型.class
。应该使用
org.springframework.ui.Model
并使用
Model.addAttribute
而不是
Model.put

出现上述错误是因为Spring找不到要与表单数据绑定的ModelAttribute

试试这个:

@RequestMapping(method = RequestMethod.GET) 
    public String viewModificationForm(Model model) {
        Hito hitoForm = new Hito();
        model.addAttribute("hitoForm", hitoForm);
        return "main"; 
    } 
html
页面的
表单中添加
$modeldattribute=“hitoForm”
。它会解决你的问题

    <form:form role="form" action="modifyHito" method="post" 
    modelAttribute="hitoForm">
html
页面的
表单中添加
$modeldattribute=“hitoForm”
。它会解决你的问题

    <form:form role="form" action="modifyHito" method="post" 
    modelAttribute="hitoForm">