麻烦各位老师指导下,我想实现jsp显示照片功能。
我的图片是存放在Tomcat\webapps一个目录下,前台jsp查询到数据库存图片的URL路径,
jsp问题代码如下:
${item.imageUrl }
${item.imageLink }
${item.createtime }
${item.createperson }
查询报错:
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 and RFC 3986
at org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:467)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:294)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:764)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1388)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
九月 23, 2018 9:49: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 and RFC 3986
at org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:467)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:294)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:764)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1388)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
我已经找到原因,src需要使用GET而不是Post,后来因图片存放在tomcat服务器目录下,我直接在xml中配置了映射关系,前台JSP直接获取到了。
https://blog.csdn.net/cwzhsi/article/details/43417357
controller方法如下:
@RequestMapping(value="getpic", method = RequestMethod.POST, produces = {"application/vnd.ms-excel;charset=UTF-8"})
public String getpic(String path, HttpServletResponse response) throws IOException {
System.out.println("path:"+path);
response.setContentType("image/jpeg/jpg/png/gif/bmp/tiff/svg"); // 设置返回内容格式
path=new String(path.getBytes("ISO-8859-1"),"UTF-8");
File file = new File(path); //括号里参数为文件图片路径
if(file.exists()){ //如果文件存在
InputStream in = new FileInputStream(path); //用该文件创建一个输入流
OutputStream os = response.getOutputStream(); //创建输出流
byte[] b = new byte[1024];
while( in.read(b)!= -1){
os.write(b);
}
in.close();
os.flush();
os.close();
}
return null;
}
我在这个方法加断点,debug不进,先报错:
信息: 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 and RFC 3986
at org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:467)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:294)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:764)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1388)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
jsp代码如下:
<tr class="result-table-head">
<th style="width:80px;"><input type="checkbox" onclick="checkAll(this)" id="all"/>全选</th>
<th style="width:300px;">url</th>
</tr>
<c:forEach items="${itemsList }" var="item">
<tr>
<td style="width:80px;"><input type="checkbox" name="items_id" onclick="selectProduct()"value="${item.id}" /></td>
<td style="width:300px;">${item.imageUrl }</td>
<td style="width:100px;">${item.imageLink }</td>
<td style="width:100px;">${item.createtime }</td>
<td style="width:100px;">${item.createperson }</td>
<td style="width:100px;">
<img style="width:100%;" src="getpic.api?path=${item.imageUrl }" /> </td>
</tr>
</c:forEach>