tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Yuri Kazakov <ykaza...@panache.co.jp>
Subject Servlet - JSP POST data problem.
Date Tue, 17 Oct 2000 01:38:06 GMT
Hello All,

I have a servlet that reads POST data, implements business 
logic and calls JSP (RequestDispatcher.forward()) only for HTML decoration.
JSP doesn't try to access any GET/POST parameters but anyway
Jasper JSP servlet checks POST data and raise:
	java.lang.IllegalArgumentException: Short Read.

I found out that many people already had the same problem as me, for example:
	Re: HttpUtil.parsePostData() and JSP problem, May 11 2000
	RE: HttpUtil.parsePostData() and JSP problem, May 11 2000
	Problem processing a Post with getRequestDispatcher.include(), Feb 14 2000

By the way, people from servlet mailing list (SERVLET-INTEREST@java.sun.com)
think that 
this Tomcat/Jasper's behavior is not correct:
	Re: RequestDispatcher and POST data, 6 Jun 2000

I didn't find any solutions in mailing lists
and changed ContentLength to avoid the problem.
In brief:
	int	c_length = request.getContentLength();
	request.getRealRequest().setContentLength(0);
	go.getRequestDispatcher(path).forward(request, response);
	request.getRealRequest().setContentLength(c_length);


Could anyone from Tomcat developers confirm that this 
intrusion to Tomcat is safe and will not cause any troubles.

Thanks in advance.

Sincerely,
Yuri.


---------------------------------------------------

				/* change Content-Length */
int	c_length = request.getContentLength();
if
(session.getClass().getName().equals("org.apache.tomcat.session.StandardSession"))
{
				/* Tomcat servlet container! */
	Method[]	ms = request.getClass().getMethods();	/* reflection games to make it
*/
	for (int i = 0; i < ms.length; i++)			/*    compilable in non-tomcat */
		if (ms[i].getName().equals("getRealRequest")) {	/*           class environment
*/
			Object	par = ms[i].invoke(request, new Object[0]);
			par.getClass().getMethod("setContentLength", new Class[] { int.class }).
				invoke(par, new Object[] { new Integer(0) }); }}

				/* dispatch to JSP page */
go.getRequestDispatcher(path).forward(request, response);

				/* change back */
if
(session.getClass().getName().equals("org.apache.tomcat.session.StandardSession"))
{
	Method[]	ms = request.getClass().getMethods();	/* reflection games to make it
*/
	for (int i = 0; i < ms.length; i++)			/*    compilable in non-tomcat */
		if (ms[i].getName().equals("getRealRequest")) {	/*           class environment
*/
			Object	par = ms[i].invoke(request, new Object[0]);
			par.getClass().getMethod("setContentLength", new Class[] { int.class }).
				invoke(par, new Object[] { new Integer(c_length) }); }}

---------------------------------------------------

Mime
View raw message