我没有得到我的查询字符串参数从jsp到控制器。
以下是我的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 Status 400错误“必需的字符串参数'fileName'不存在”。 它正在从查询字符串中删除? 向前。 请指导。 提前致谢。
I am not getting my query string parameters from jsp to Controller.
Below is my uploadSuccess.jsp code:
<!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 method is: //http://localhost:8080/pipeline/readQRCode
@RequestMapping(value = "/readQRCode", method = RequestMethod.GET) public String readQRCode(Model model, @RequestParam(value = "fileName", required = true) String fileName) { ........................ }The url query string that I see in view source of jsp is: action="http://localhost:8080/pipeline/readQRCode?fileName=Paper+Scan.pdf" >
However, when I submit the jsp form, it gives me Http Status 400 error "Required String parameter 'fileName' is not present". It is dropping the query string from ? onward. Please guide. Thanks in advance.
最满意答案
正如我可以从代码中看到的那样,发布此部分可能是错误的:
<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}"/>" >所以你可以试试这个解决方案适用于你的代码,当然你需要删除第一个解决方案。
as i can see from the code you post this part maybe is wrong:
<c:url var="formActionURL" value="http://localhost:8080/scanpipeline/readQRCode">Because when you submit you will be redirect to this url, and so you don't have any query string.
Try change with adding a hidden input to your form with value of query string. So being a get method the value of this input will be in your URL as query string.
Like this:
<form method="GET" action="${formActionURL}" > <input type="hidden" value=${fileName} /> <h3> File Uploaded Successfully! </h3>Last Edit:
In answer to your comment, your original code was incorrect because you was using tag in a wrong way.
This is the correct form:
<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}"/>" >So you can try also this solution applied to your code, of course you need to remove the first solution.
更多推荐
发布评论