繁体   English   中英

在jsp中对Spring Controller进行GET操作时,将删除url查询字符串参数

[英]On GET action in jsp to Spring Controller drops the url query string parameters

我没有从jsp到Controller获取查询字符串参数。

以下是我的uploadSuccess.jsp代码:

<!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=ISO-8859-1"  pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page session="false" %>

<html>
<head>
<title>File Upload Success</title>
</head>
<body>
<c:url var="formActionURL" value="http://localhost:8080/scanpipeline/readQRCode">
<c:param name="fileName" value="${fileName}" />
</c:url>

<form method="GET"  action="${formActionURL}" > 

<h3>
File Uploaded Successfully!
</h3>

<strong>File name is :<%= request.getAttribute("fileName") %> !!</strong> 
<strong>Total number of data read from file: <%=request.getAttribute("filedata") %> !! 
</strong><br>
<p></p> 
If you want to see QR Code information in the upload file, click 'Ok'   <br> 
<input type="submit" value="Ok">
</form>
</body>
</html>

Spring Controller方法是:// http:// localhost:8080 / pipeline / readQRCode

@RequestMapping(value = "/readQRCode",  method = RequestMethod.GET)
public String readQRCode(Model model, @RequestParam(value = "fileName", required = true) String fileName)
{
........................
}

我在jsp的查看源中看到的url查询字符串是:action =“ http:// localhost:8080 / pipeline / readQRCode?fileName = Paper + Scan.pdf”>

但是,当我提交jsp表单时,它给了我HTTP状态400错误“不存在必需的字符串参数'fileName'”。 它从删除查询字符串? 向前。 请指导。 提前致谢。

正如我从您发布此部分的代码中看到的那样,这可能是错误的:

<c:url var="formActionURL" value="http://localhost:8080/scanpipeline/readQRCode">

因为当您提交时,您将被重定向到该URL,因此您没有任何查询字符串。

尝试通过向查询表单中添加一个隐藏的输入值来更改更改。 因此,作为一种get方法,此输入的值将作为查询字符串出现在您的URL中。

像这样:

<form method="GET"  action="${formActionURL}" > 

<input type="hidden" value=${fileName} />
<h3>
File Uploaded Successfully!
</h3>

最后编辑:

为了回答您的评论,您的原始代码不正确,因为您使用标签的方式不正确。

这是正确的形式:

<c:url value="/index.jsp" var="myURL">
<c:param name="trackingId" value="1234"/>
<c:param name="reportType" value="summary"/>
</c:url>

<form method="GET"  action="<c:import url="${myURL}"/>" > 

因此,您也可以尝试将此解决方案应用于您的代码,当然您需要删除第一个解决方案。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM