Note: further occurrences of HTTP header parsing errors will be logged at DEBUG level.错误解决办法

由一个Servlet跳转到另一个Servlet,报出的错误:

信息: Error parsing HTTP request header

 Note: further occurrences of HTTP header 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:452)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:667)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:745)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1455)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)


代码片段如下:

IndexServlet:

public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	response.setContentType("text/html;charset=UTF-8");
	PrintWriter out = response.getWriter();
		
	out.write("当前商品有:
"); List list = Products.getAll(); for(String s:list){ out.write(s); out.write("购买
"); } }

BuyServlet:

public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	// 获取IndexServlet传过来的商品
	String name = request.getParameter("name");
	// 因为传过来的是汉字,所以需要重新编码?
	//name = new String(name.getBytes("ISO-8859-1"), "UTF-8");
		
	// getSession():没有Session,则创建Session;有Session,则直接获取。
	HttpSession session = request.getSession();
	Object obj = session.getAttribute(Constant.My_Car);
	if (obj != null){   // 如果有购物车,则取出购物车,放商品。
		List list = (List)obj;
		list.add(name);
	}else{				// 如果没有购物车,则创建一个购物车
		List list = new ArrayList();
		list.add(name);
		session.setAttribute(Constant.My_Car, list);
	}
		
	response.setContentType("text/html;charset=UTF-8");
	PrintWriter out = response.getWriter();
	out.write("您当前购买商品为:" + name + "
"); }



当点击购买时就出错了。

Note: further occurrences of HTTP header parsing errors will be logged at DEBUG level.错误解决办法_第1张图片

Note: further occurrences of HTTP header parsing errors will be logged at DEBUG level.错误解决办法_第2张图片


最终解决办法是:

将地址栏的:localhost:8080/09_Session/servlet/IndexServlet

改成:127.0.0.1:8080/09_Session/servlet/IndexServlet


参考资料:http://bbs.csdn.net/topics/390688735

原因未知!



你可能感兴趣的:(问题解决笔记)