Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 376
  • Last Modified:

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();
     
        }
    }
   
       
0
asaliu
Asked:
asaliu
  • 7
  • 4
  • 3
  • +2
2 Solutions
 
radarshCommented:
What is the error you are getting? If you have any exception, post it's stack trace.

________
radarsh
0
 
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)
0
 
objectsCommented:
looks like it is not an object stream.
If its not an object stream you can't use it with an ObjectInputStream
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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.";
           
        }
       
    }
0
 
objectsCommented:
>             new searchPopUp("Reference Check Result", index);

whats this do?
0
 
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.
0
 
objectsCommented:
does it open an ObjectOutputStream? (it needs to)
0
 
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();
0
 
objectsCommented:
what else is in in searchPopup()'s constructor?
0
 
Mayank SAssociate Director - Product EngineeringCommented:
What objects does the Vector contain?
0
 
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
0
 
Leo EikelmanCommented:
Try this,

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

See if that fixes the problem.

cheers,

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

0
 
Leo EikelmanCommented:
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

0
 
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,
0
 
Leo EikelmanCommented:
No problem at all.

Happy programming.

Leo
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 7
  • 4
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now