Link to home
Start Free TrialLog in
Avatar of asaliu
asaliu

asked on

Servlet Problem , ObjectInputStream ...

Hi Everybody,
 
The following doGet method is giving me problems.
If I comment out the statements:
ObjectInputStream input=new ObjectInputStream(request.getInputStream());  

and the other code dependant on it, the servlet works.

What might be the problem?

Thanks
Mimo


public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
       ObjectInputStream input=new ObjectInputStream(request.getInputStream());  
        /**
         * Sets the content type
         */          
        response.setContentType("text/html");
   
  try {
         
     PrintWriter out = response.getWriter();
       
        out.println("<html ><head><title>Reference Check Results</title></head><body >");
         searchParam = (Vector) input.readObject();
            tableName= (String) searchParam.get(0);
            primaryCol = (String) searchParam.get(1);
            primaryKey = (String) searchParam.get(2);    
        out.println(getRecords(tableName,primaryCol,primaryKey));
        out.println("</body></html>");
        out.close();
         } catch (ClassNotFoundException ex) {
            ex.printStackTrace();
     
        }
    }
   
       
Avatar of radarsh
radarsh

What is the error you are getting? If you have any exception, post it's stack trace.

________
radarsh
Avatar of asaliu

ASKER

22-Mar-2006 21:12:28 org.apache.catalina.core.StandardWrapperValve invoke
WARNING: Servlet.service() for servlet checkServlet threw exception
java.io.EOFException
        at java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2232)
        at java.io.ObjectInputStream$BlockDataInputStream.readShort(ObjectInputStream.java:2698)
        at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:750)
        at java.io.ObjectInputStream.<init>(ObjectInputStream.java:268)
        at checkServlet.doGet(checkServlet.java:46)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
        at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:362)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
        at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
        at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
        at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
        at java.lang.Thread.run(Thread.java:595)
Avatar of Mick Barry
looks like it is not an object stream.
If its not an object stream you can't use it with an ObjectInputStream
Avatar of asaliu

ASKER

This is the method which is calling the servlet in case it helps ...

 private void  CheckReference(String table,String primaryCol, String primarykey){
       
        try {
             Vector vect =new Vector();
        vect.add(new String(table));
        vect.add(new String(primaryCol));
        vect.add(new String(primarykey));
            // Initialize URL to call the servlet
            URL url=new URL("http://localhost/WebApplication1/checkServlet");
            URLConnection servletConnection = url.openConnection();
            // Set client caching to false
            servletConnection.setUseCaches(false);
           
            // Enable I/O through the connection
            servletConnection.setDoInput(true);
            servletConnection.setDoOutput(true);
           
            ObjectOutputStream output = new ObjectOutputStream(servletConnection.getOutputStream());
           
            // vector to pass search imput {database table, primary key column, name column, primary key)
           
            output.writeObject(vect);
           
            // flush and close the output
            output.flush();
            output.close();
           
            URL   index = new URL("http://localhost/WebApplication1/checkServlet");
            new searchPopUp("Reference Check Result", index);
        } catch (MalformedURLException ex) {
            ex.printStackTrace();
        } catch(Exception e) {
            // Exception occured during search
            e.printStackTrace();
            message+="\nProblem during connection with web server\nYou might want to check"+
                    " your internet connection or if the Web Server / Database in up and running.";
           
        }
       
    }
>             new searchPopUp("Reference Check Result", index);

whats this do?
Avatar of asaliu

ASKER

This creates a jEditorPane which displays the html result from the servlet,
It uses the servlet address as you've guessed by now.
SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of asaliu

ASKER

Yes,
Pls see below:

ObjectOutputStream output = new ObjectOutputStream(servletConnection.getOutputStream());
           
            // vector to pass search imput {database table, primary key column, name column, primary key)
           
            output.writeObject(vect);
           
            // flush and close the output
            output.flush();
            output.close();
what else is in in searchPopup()'s constructor?
What objects does the Vector contain?
Avatar of asaliu

ASKER


>what else is in in searchPopup()'s constructor?

public searchPopUp(String title,URL hlpURL) {
      super(title);
      helpURL = hlpURL;
      editorpane = new JEditorPane();
      editorpane.setEditable(false);
     
     try {
        editorpane.setContentType("text/html");
          editorpane.setPage(helpURL);
     }
       catch (Exception ex) {
         ex.printStackTrace();
      }
     
      //anonymous inner listener
      editorpane.addHyperlinkListener(new HyperlinkListener() {
          public void hyperlinkUpdate(HyperlinkEvent ev) {
              try {
                  if (ev.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                      editorpane.setPage(ev.getURL());
                  }
              } catch (IOException ex) {
                  //put message in window
                  ex.printStackTrace();
              }
          }
      });
    getContentPane().add(new JScrollPane(editorpane));
    addButtons();
      // no need for listener just dispose
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);
     // dynamically set location
     calculateLocation();
     setVisible(true);
     // end constructor
}

>What objects does the Vector contain?
three String objects
Try this,

First "rebuild" the servlet - THEN "rebuild" the applet.

See if that fixes the problem.

cheers,

Leo
Avatar of asaliu

ASKER

>First "rebuild" the servlet - THEN "rebuild" the applet.
Tried it but it gives the same error stack trace

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of asaliu

ASKER

>I don't think u can set contentType when using input/output
I did suspect that.

I tried this:
got rid of

response.setContentType("text/html");

instead of trying to write html directly I posted back to the GUI requesting the result
a String which builds a html page.

then from the client I changed the jEditorPane which initially had a ulr page set into it.
Now that jEditorPane uses the String to build its html page.

That worked.

Thanks Leo,
No problem at all.

Happy programming.

Leo