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();
     
        }
    }
   
       
asaliuAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

________
radarsh
asaliuAuthor Commented:
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)
Mick BarryJava DeveloperCommented:
looks like it is not an object stream.
If its not an object stream you can't use it with an ObjectInputStream
Exploring SQL Server 2016: Fundamentals

Learn the fundamentals of Microsoft SQL Server, a relational database management system that stores and retrieves data when requested by other software applications.

asaliuAuthor Commented:
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.";
           
        }
       
    }
Mick BarryJava DeveloperCommented:
>             new searchPopUp("Reference Check Result", index);

whats this do?
asaliuAuthor Commented:
This creates a jEditorPane which displays the html result from the servlet,
It uses the servlet address as you've guessed by now.
Mick BarryJava DeveloperCommented:
does it open an ObjectOutputStream? (it needs to)
asaliuAuthor Commented:
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();
Mick BarryJava DeveloperCommented:
what else is in in searchPopup()'s constructor?
Mayank SAssociate Director - Product EngineeringCommented:
What objects does the Vector contain?
asaliuAuthor Commented:

>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
Leo EikelmanDirector, IT and Business DevelopmentCommented:
Try this,

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

See if that fixes the problem.

cheers,

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

Leo EikelmanDirector, IT and Business DevelopmentCommented:
Try this

Get rid of

response.setContentType("text/html");


I don't think u can set contentType when using input/output


hope that helps,

Leo

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
asaliuAuthor Commented:
>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,
Leo EikelmanDirector, IT and Business DevelopmentCommented:
No problem at all.

Happy programming.

Leo
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.