tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eddie tsai <t...@medusa.nn.com>
Subject pass arguments to servlet in tomcat 4.0
Date Wed, 21 Feb 2001 18:41:50 GMT
i am currently using tomcat 4.0 milestone 5. i am trying to make a
servlet that can take arguments when the servlet is invoked from another
java application. the way i did it worked with tomcat 3.2 but not with
4.0. it gave me the "stream is closed" error when the servlet is trying
to read from the servlet request inputstream. has mechanism underneath
been changed? or is that not how it is supposed to be done? 

thanks for your help,

eddie
--

---------
here is the error i got:

java.io.IOException: This input stream has been closed
	at
org.apache.catalina.connector.RequestStream.available(RequestStream.java:182)
	at TestServlet.service(TestServlet.java:11)
	at
org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:519)
	at
org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:292)
	at
org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerServlet.java:386)
	at
org.apache.catalina.servlets.InvokerServlet.doPost(InvokerServlet.java:180)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
	at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:251)
	at
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:977)
	at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:196)
	at
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:977)
	at
org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2038)
	at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
	at
org.apache.catalina.valves.ValveBase.invokeNext(ValveBase.java:242)
	at
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:414)
	at
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:975)
	at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:159)
	at
org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:977)
	at
org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:811)
	at
org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:890)
	at java.lang.Thread.run(Thread.java:484)

------------------
here is the code fragment for the application invoking the servlet and
trying to pass an arguments to the servlet:

class TestApplication
{
...
    public void main(String[] args)
    {
		try
		{
			URL url = new
URL("http://localhost:8080/RS/servlet/TestServlet");
			URLConnection connection = url.openConnection();
			connection.setDoOutput(true);
			connection.setDoInput(true);
			connection.setUseCaches(false);

   			ObjectOutputStream oos = new ObjectOutputStream(
   				connection.getOutputStream());
			// Try to pass an argument to the servlet.
			oos.writeObject("first argument");
			oos.flush();
			
  			connection.getInputStream();
			System.out.println("done with testservlet");
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
    }
}

------------------
here is the code for the servlet to be invoked:

class TestServlet extends GenericServlet
{
	public void service(
		ServletRequest request,
		ServletResponse response) throws ServletException,
IOException
	{
		System.out.println("ready to test input stream");
		// Trying to see if the 'argument' is available to be
read.
		java.io.InputStream is = request.getInputStream();
		// The error will occur when doing is.available().
		System.out.println("successfully got input stream and
available="+
			is.available());
	}
}



Mime
View raw message