Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.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
Spring MVC webapp HTTP状态400_Spring_Http - Fatal编程技术网

Spring MVC webapp HTTP状态400

Spring MVC webapp HTTP状态400,spring,http,Spring,Http,我正在开发一个带有Spring和hibernate的webapp。我有一个简单的表单,包含一个文本字段和一个选择: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <%@ page language="java" contentType="text/html; charset=utf8" pageEncoding=

我正在开发一个带有Spring和hibernate的webapp。我有一个简单的表单,包含一个文本字段和一个选择:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"     "http://www.w3.org/TR/html4/loose.dtd">
<%@ page language="java" contentType="text/html; charset=utf8" pageEncoding="utf8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ page trimDirectiveWhitespaces="true" %>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="Content-Language" content="English"/>
    <!--    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 
        <meta http-equiv="Content-Language" content="es"/>-->
    <link rel="stylesheet" media="all" href="<c:url value="/resources/site.css"/>">
    <title>Nuevo expediente</title>
</head>
<body>
    <h2>Nuevo expediente</h2>
    <form:form modelAttribute="expediente" method="post">
<table>
    <tr>
        <td>Tipo de expediente:</td>
        <td>
            <form:select path="tipoExpediente">
                <form:option value="-" label="Seleccione un tipo"/>
                <form:options items="${expedientes}" itemValue="tipoExpediente" itemLabel="tipoExpediente" />
            </form:select>
            <form:errors path="tipoExpediente" element="span"/>
        </td>
    </tr>
    <tr>
        <td>Estado:</td>
        <td>
            <form:input path="estado"/>
            <form:errors path="estado" element="span"/>
        </td>
    </tr>
</table>
<br/>
<input type="submit" value="Create" />
</form:form>
</body>
</html>
我已经了解到这可能是由requestparams引起的,但我没有使用它们

这是我的控制器:

package com.atlantis.atecliente.controller;

import com.atlantis.atecliente.model.Book;
import com.atlantis.atecliente.model.Expediente;
import com.atlantis.atecliente.model.TipoExpediente;
import com.atlantis.atecliente.repository.ExpedienteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class ExpedienteController {

@Autowired
protected ExpedienteService service;

@RequestMapping(value = {"/*", "/expedientes"})
public String getExpedientes(Model model) {
    List<Expediente> expedientes = service.getExpedientes();
    model.addAttribute("expedientes", expedientes);
    return "expediente";
}

@RequestMapping(value = "nuevo-expediente")
public String createExpedienteGet(Model model) {
    model.addAttribute("expediente", new Expediente());
    List<TipoExpediente> tiposExpediente = service.getTiposExpedientes();
//        List<String> canales = service.getCanales();
    model.addAttribute("expedientes", tiposExpediente);
//        model.addAttribute("canales", canales);
    return "nuevo-expediente";
}

@RequestMapping(value = "nuevo-expediente", method = RequestMethod.POST)
public String createExpedientePost(@ModelAttribute("expediente") Expediente expediente)     {
    service.createExpediente(expediente);
    return "redirect:expedientes";
}
}
要帮忙吗


谢谢

我已经解决了这个问题。问题在于控制器方法映射到url

我将函数CreateEquipmentPost修改为:

更改是添加BindingResult作为参数


我希望这可以帮助其他人。

我已经解决了这个问题。问题在于控制器方法映射到url

我将函数CreateEquipmentPost修改为:

更改是添加BindingResult作为参数


我希望这可以帮助其他人。

当控制器方法的参数设置不正确时,似乎有人可以获得这样的错误状态。 例如,由于referer头的名称错误(它被称为referer),所以我有相同的名称


当控制器方法的参数设置不正确时,似乎有人可以获得这样的错误状态。 例如,由于referer头的名称错误(它被称为referer),所以我有相同的名称


显示您的post有效负载和
便利类。添加了便利类。抱歉,但post有效负载是什么?实际发送到服务器的是什么。还要启用调试日志记录。这样你就可以知道你的请求出了什么问题。您可能还想发布相关的日志,以便其他人也可以查看它。问题是,当我调试de应用程序时,任何消息都会被记录。。。唯一的线索是,当我在函数publicstringcreateventigateget(Model-Model)的第一行放置断点时,它永远不会到达。。。因此,映射失败…显示您的post有效负载和
权宜类。添加了权宜类。抱歉,但post有效负载是什么?实际发送到服务器的是什么。还要启用调试日志记录。这样你就可以知道你的请求出了什么问题。您可能还想发布相关的日志,以便其他人也可以查看它。问题是,当我调试de应用程序时,任何消息都会被记录。。。唯一的线索是,当我在函数publicstringcreateventigateget(Model-Model)的第一行放置断点时,它永远不会到达。。。所以映射失败了。。。。
package com.atlantis.atecliente.controller;

import com.atlantis.atecliente.model.Book;
import com.atlantis.atecliente.model.Expediente;
import com.atlantis.atecliente.model.TipoExpediente;
import com.atlantis.atecliente.repository.ExpedienteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class ExpedienteController {

@Autowired
protected ExpedienteService service;

@RequestMapping(value = {"/*", "/expedientes"})
public String getExpedientes(Model model) {
    List<Expediente> expedientes = service.getExpedientes();
    model.addAttribute("expedientes", expedientes);
    return "expediente";
}

@RequestMapping(value = "nuevo-expediente")
public String createExpedienteGet(Model model) {
    model.addAttribute("expediente", new Expediente());
    List<TipoExpediente> tiposExpediente = service.getTiposExpedientes();
//        List<String> canales = service.getCanales();
    model.addAttribute("expedientes", tiposExpediente);
//        model.addAttribute("canales", canales);
    return "nuevo-expediente";
}

@RequestMapping(value = "nuevo-expediente", method = RequestMethod.POST)
public String createExpedientePost(@ModelAttribute("expediente") Expediente expediente)     {
    service.createExpediente(expediente);
    return "redirect:expedientes";
}
}
package com.atlantis.atecliente.model;

import java.util.Date;
import javax.persistence.*;

@Entity
@Table(name="Expediente")
public class Expediente {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int codExpediente;

@ManyToOne
@JoinColumn(name = "tipoExpediente")
private TipoExpediente tipoExpediente;

@ManyToOne
@JoinColumn(name = "estadoExpediente")
private EstadoExpediente estadoExpediente;

@ManyToOne
@JoinColumn(name = "expedientePadre")
private Expediente expedientePadre;

@ManyToOne
@JoinColumn(name = "tipoRelacion")
private TipoRelacion tipoRelacion;

@ManyToOne
@JoinColumn(name = "canalEntrada")
private CanalExpediente canalEntrada;

@ManyToOne
@JoinColumn(name = "idiomaEntrada")
private IdiomaExpediente idiomaEntrada;

@ManyToOne
@JoinColumn(name = "idiomaSalida")
private IdiomaExpediente idiomaSalida;

@ManyToOne
@JoinColumn(name = "tipoResolucion")
private TipoResolucion tipoResolucion;

@ManyToOne
@JoinColumn(name = "canalSalida")
private CanalExpediente canalSalida;

@Column(length = 30)
private String estado;

@Column(length = 10)
private String numeroSerie;

@Column(length = 10)
private String numeroHoja;

@Temporal(javax.persistence.TemporalType.TIMESTAMP)
private Date fechaRedaccion;

@Temporal(javax.persistence.TemporalType.TIMESTAMP)
private Date fechaRecepcion;

@Column(length = 200)
private String asunto;

@Column (length = 1000)
private String descripcion;

@Column(length = 20)
private String usuarioRegistro;

@Temporal(javax.persistence.TemporalType.DATE)
private Date fechaRegistro;

@Column (length = 20)
private String usuarioModificacion;

@Temporal(javax.persistence.TemporalType.TIMESTAMP)
private Date fechaModificacion;

@Column (length = 20)
private String usuarioCierre;

@Temporal(javax.persistence.TemporalType.TIMESTAMP)
private Date fechaCierre;

public int getCodExpediente() {
    return codExpediente;
}

public void setCodExpediente(int codExpediente) {
    this.codExpediente = codExpediente;
}

public EstadoExpediente getEstadoExpediente() {
    return estadoExpediente;
}

public void setEstadoExpediente(EstadoExpediente estadoExpediente) {
    this.estadoExpediente = estadoExpediente;
}

public Expediente getExpedientePadre() {
    return expedientePadre;
}

public void setExpedientePadre(Expediente expedientePadre) {
    this.expedientePadre = expedientePadre;
}

public TipoRelacion getTipoRelacion() {
    return tipoRelacion;
}

public void setTipoRelacion(TipoRelacion tipoRelacion) {
    this.tipoRelacion = tipoRelacion;
}

public CanalExpediente getCanalEntrada() {
    return canalEntrada;
}

public void setCanalEntrada(CanalExpediente canalEntrada) {
    this.canalEntrada = canalEntrada;
}

public IdiomaExpediente getIdiomaEntrada() {
    return idiomaEntrada;
}

public void setIdiomaEntrada(IdiomaExpediente idiomaEntrada) {
    this.idiomaEntrada = idiomaEntrada;
}

public IdiomaExpediente getIdiomaSalida() {
    return idiomaSalida;
}

public void setIdiomaSalida(IdiomaExpediente idiomaSalida) {
    this.idiomaSalida = idiomaSalida;
}

public TipoResolucion getTipoResolucion() {
    return tipoResolucion;
}

public void setTipoResolucion(TipoResolucion tipoResolucion) {
    this.tipoResolucion = tipoResolucion;
}

public CanalExpediente getCanalSalida() {
    return canalSalida;
}

public void setCanalSalida(CanalExpediente canalSalida) {
    this.canalSalida = canalSalida;
}

public String getUsuarioRegistro() {
    return usuarioRegistro;
}

public void setUsuarioRegistro(String usuarioRegistro) {
    this.usuarioRegistro = usuarioRegistro;
}

public String getNumeroSerie() {
    return numeroSerie;
}

public void setNumeroSerie(String numeroSerie) {
    this.numeroSerie = numeroSerie;
}

public String getNumeroHoja() {
    return numeroHoja;
}

public void setNumeroHoja(String numeroHoja) {
    this.numeroHoja = numeroHoja;
}

public Date getFechaRedaccion() {
    return fechaRedaccion;
}

public void setFechaRedaccion(Date fechaRedaccion) {
    this.fechaRedaccion = fechaRedaccion;
}

public Date getFechaRecepcion() {
    return fechaRecepcion;
}

public void setFechaRecepcion(Date fechaRecepcion) {
    this.fechaRecepcion = fechaRecepcion;
}

public String getAsunto() {
    return asunto;
}

public void setAsunto(String asunto) {
    this.asunto = asunto;
}

public String getDescripcion() {
    return descripcion;
}

public void setDescripcion(String descripcion) {
    this.descripcion = descripcion;
}

public Date getFechaRegistro() {
    return fechaRegistro;
}

public void setFechaRegistro(Date fechaRegistro) {
    this.fechaRegistro = fechaRegistro;
}

public String getUsuarioModificacion() {
    return usuarioModificacion;
}

public void setUsuarioModificacion(String usuarioModificacion) {
    this.usuarioModificacion = usuarioModificacion;
}

public Date getFechaModificacion() {
    return fechaModificacion;
}

public void setFechaModificacion(Date fechaModificacion) {
    this.fechaModificacion = fechaModificacion;
}

public String getUsuarioCierre() {
    return usuarioCierre;
}

public void setUsuarioCierre(String usuarioCierre) {
    this.usuarioCierre = usuarioCierre;
}

public Date getFechaCierre() {
    return fechaCierre;
}

public void setFechaCierre(Date fechaCierre) {
    this.fechaCierre = fechaCierre;
}

public TipoExpediente getTipoExpediente() {
    return tipoExpediente;
}

public void setTipoExpediente(TipoExpediente tipoExpediente) {
    this.tipoExpediente = tipoExpediente;
}

public String getEstado() {
    return estado;
}

public void setEstado(String estado) {
    this.estado = estado;
}
}
public String createExpedientePost(@ModelAttribute("expediente") Expediente expediente, BindingResult result) {
public String foo(@RequestHeader(value = "referer") final String referer) {}