gpt4 book ai didi

java - 提交表单时收到错误消息 : "The request sent by the client was syntactically incorrect"

转载 作者:行者123 更新时间:2023-11-29 09:08:53 26 4
gpt4 key购买 nike

我正在开发一个使用 Spring 框架 3.1.0 版开发的 Web 应用程序。

我有一个 JSP 页面,其中包含一个允许用户从 SELECT 下拉列表框中选择国家/地区的表单。提交表单应该运行数据库查询并返回相同的 JSP 页面,其中包括表单以及所选国家的作者和研究所数据的 HTML 表格。

这是 JSP 页面的部分代码:

<c:url var="submitUrl" value="/authorsInstitutes.htm"/>
<form:form action="${submitUrl}" method="POST">
<select id="countryCode">
<option value="-1">-- Please Select --</option>
<c:forEach var="country" items="${countryList}">
<option value="${country.countryCode}">${country.countryName}</option>
</c:forEach>
</select>
<input type="submit"/>
</form:form>

下面是来自 Controller 类的代码,用于处理“GET”和“POST”请求的方法:

@RequestMapping(value = "/authorsInstitutes", method = RequestMethod.GET)
public ModelAndView displayAuthorsInstitutesForm() {
ModelAndView mav = new ModelAndView("authorsInstitutes");

List<Country> countryList = countrySrv.findAll();
mav.addObject("countryList", countryList);

return mav;
}

@RequestMapping(value = "/authorsInstitutes", method = RequestMethod.POST)
public ModelAndView displayAuthorsInstitutes(
@RequestParam(value = "countryCode") String country) {
ModelAndView mav = new ModelAndView("authorsInstitutes");

List<Country> countryList = countrySrv.findAll();
mav.addObject("countryList", countryList);

if (country != null && !country.trim().equals("")) {
List<Affiliation> affiliationList =
affiliationSrv.getAffiliationsByCountryCode(country);
mav.addObject("affiliationList", affiliationList);
}

return mav;
}

“GET”请求工作正常,但是当我选择一个国家并提交表单时,我收到 404 错误消息:

HTTP Status 400 -
type Status report
message
description The request sent by the client was syntactically incorrect ().

我确信这很简单,但就我的生活而言,我就是看不出我做错了什么。如果您能帮我解决这个问题,我将不胜感激。

最佳答案

使用 Firebug 或任何类似工具,检查 countryCode 参数是否传递给服务器。我还看到请求映射是

@RequestMapping(value = "/authorsInstitutes", method = RequestMethod.POST)

将请求发送到 /authorsInstitutes.htm

关于java - 提交表单时收到错误消息 : "The request sent by the client was syntactically incorrect",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13422093/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com