我向控制器发送user=> (macroexpand `(let [a# 0] a#))
(let* [a__3__auto__ 0] a__3__auto__)
时遇到问题。当我按下提交按钮时,它显示400错误。当我尝试在POST方法中将smth输出到控制台时,它无法显示它。为什么控制器没有得到我的表格?感谢名单!
这是我的JSP页面
<form>
这是我的控制器方法。
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://www.springframework.org/security/tags"
prefix="sec"%>
<%@page language="java" session="true"%>
<%
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
%>
<!DOCTYPE html>
<fmt:requestEncoding value="utf-8" />
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Поиск оппонента | Haine and Vold</title>
<link rel="shortcut icon" href="<c:url value="/resources/faviicon/iconHV.ico"/>" type="image/x-icon">
<link href="<c:url value="/resources/bootstrap/bootstrap.css"/>"
rel="stylesheet" type="text/css">
<link href="<c:url value="/resources/CSS/styles.css"/>" rel="stylesheet"
type="text/css">
</head>
<body>
<div class="container">
<img class="img-responsive logo" src="/app/resources/logo.jpg">
</div>
<h5 class="text-center noparamserror">${noparams}</h5>
<c:url var="getSearch" value="/user/search" />
<br>
<div class="container text-center">
<form:form class="form-inline centerBlock" modelAttribute="users"
method="POST" action="/app/user/search" accept-charset="utf-8">
<div class="form-group">
<label class="control-label" for="weight"><spring:message
code="label.searchparamweight" /></label>
<form:select multiple="" class="form-control input-sm" path="weight"
name="weight">
<form:option value=""></form:option>
<form:option value="40"></form:option>
<form:option value="50"></form:option>
<form:option value="60"></form:option>
<form:option value="70"></form:option>
<form:option value="80"></form:option>
<form:option value="90"></form:option>
<form:option value="100"></form:option>
<form:option value="110"></form:option>
<form:option value="120"></form:option>
</form:select>
</div>
<div class="form-group">
<label class="control-label" for="gender"><spring:message
code="label.gender" /></label>
<form:select multiple="" class="form-control input-sm" name="gender"
path="gender">
<form:option value=""></form:option>
<form:option value="Мужской"></form:option>
<form:option value="Женский"></form:option>
</form:select>
</div>
<div class="form-group">
<label class="control-label" for="place"><spring:message
code="label.place" /></label>
<form:select class="form-control input-small" name="place"
path="place">
<form:option value=""></form:option>
<form:option value="Дзержинский"></form:option>
<form:option value="Киевский"></form:option>
<form:option value="Комминтерновский"></form:option>
<form:option value="Лененский"></form:option>
<form:option value="Московский"></form:option>
<form:option value="Октябрский"></form:option>
<form:option value="Орджоникидзевский"></form:option>
<form:option value="Фрунзенский"></form:option>
<form:option value="Холодная гора"></form:option>
<form:option value="Червонозаводской"></form:option>
</form:select>
</div>
<div class="form-group">
<label class="control-label" for="age"><spring:message
code="label.searchparamage" /></label>
<form:select multiple="" class="form-control input-small" name="age"
path="age">
<form:option value=""></form:option>
<form:option value="19"></form:option>
<form:option value="20"></form:option>
<form:option value="21"></form:option>
<form:option value="22"></form:option>
<form:option value="23"></form:option>
<form:option value="24"></form:option>
<form:option value="25"></form:option>
<form:option value="26"></form:option>
<form:option value="27"></form:option>
<form:option value="28"></form:option>
<form:option value="29"></form:option>
<form:option value="30"></form:option>
<form:option value="31"></form:option>
<form:option value="32"></form:option>
<form:option value="33"></form:option>
<form:option value="34"></form:option>
<form:option value="35"></form:option>
<form:option value="36"></form:option>
<form:option value="37"></form:option>
<form:option value="38"></form:option>
<form:option value="39"></form:option>
<form:option value="40"></form:option>
<form:option value="41"></form:option>
<form:option value="42"></form:option>
<form:option value="43"></form:option>
<form:option value="44"></form:option>
<form:option value="45"></form:option>
</form:select>
</div>
<button class="btn btn-success" type="submit">
<spring:message code="label.search" />
</button>
</form:form>
</div>
<br>
<div class="scrollTableSearch">
<c:if test="${!empty listUsersSort}">
<table
class="table table-striped table-bordered table-condensed table-hover">
<tr>
<th><spring:message code="label.name" /></th>
<th><spring:message code="label.surname" /></th>
<th><spring:message code="label.gender" /></th>
<th><spring:message code="label.weight" /></th>
<th><spring:message code="label.height" /></th>
<th><spring:message code="label.sport" /></th>
<th><spring:message code="label.place" /></th>
</tr>
<c:forEach items="${listUsersSort}" var="users">
<tr>
<td><a href="<c:url value='/user/search/${users.username}'/>"
target="_blank"> ${users.name}</a></td>
<td>${users.surname}</td>
<td>${users.gender}</td>
<td>${users.weight}</td>
<td>${users.height}</td>
<td>${users.sport}</td>
<td>${users.place}</td>
</tr>
</c:forEach>
</table>
</c:if>
</div>
</body>
<script src="<c:url value="/resources/Jquery/jquery-2.1.4.min.js"/>"
type="text/javascript"></script>
<script src="<c:url value="/resources/bootstrap/bootstrap.js"/>"
type="text/javascript"></script>
</html>
答案 0 :(得分:1)
您收到错误是因为您的代码介于两者之间,使用表单支持bean或绑定请求中的参数。你应该删除
表单中的modelAttribute
和path
属性。
或者从请求中删除@RequestParam
带注释的参数,并使用weight
,age
,place
,gender
创建form-backing对象属性,并将对象添加到使用@ModelAttribute("users")
答案 1 :(得分:0)
在您的JSP页面中,实际上您在向控制器发出请求时缺少Context Root。
<form:form class="form-inline centerBlock" modelAttribute="users"
method="POST" action="/app/user/search" accept-charset="utf-8">
在这种情况下,请求网址为:
因此,要解决此问题,您可以将上下文根包含在操作中:
<form:form class="form-inline centerBlock" modelAttribute="users"
method="POST" action="/your-context-root/app/user/search" accept-charset="utf-8">
或以这种方式写作:
<spring:url value="/app/user/search" var="formUrl"/>
<form:form class="form-inline centerBlock" modelAttribute="users"
method="POST" action="${formUrl}" accept-charset="utf-8">