我正在尝试将jsp上的表单中的数据提交给我的servlet,以在数据库中进一步处理它。
表格如下:
<form id="example" name="example" class="normalForm1" action="example" method="Post">
<input type="hidden" name="do_form" value="doTask">
<input type="hidden" name="trial0" id="trial0">
<br/><input id="nextPage" type="submit" value="Continue" hidden></form>
“ trial1”输入中存储的数据如下:
document.getElementById("trial0").value = [1,1,1,"word1|word2|word3|word4|word5",1,99]
在服务器端,此代码获取数据:
String trial0 = req.getParameter("trial0");
在服务器日志中,出现以下异常:
23-Apr-2020 12:22:05.100 INFORMATION [https-jsse-nio-8443-exec-56] org.apache.coyote.http11.Http11Processor.service Error parsing HTTP request header
Note: further occurrences of HTTP request parsing errors will be logged at DEBUG level.
java.lang.IllegalArgumentException: Invalid character found in the request target. The valid characters are defined in RFC 7230
at org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:416)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:260)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1639)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
有趣的是,有时提交工作不会引发异常,有时确实会引发异常(看来这是随机的)。
我对任何想法都很高兴。
最诚挚的祝福
您正在尝试将数组分配给字符串变量。
代替做
document.getElementById("trial0").value = JSON.stringify([1,1,1,"word1|word2|word3|word4|word5",1,99]);