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. getInputSt ream());
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. getInputSt ream());
/**
* Sets the content type
*/
response.setContentType("t ext/html") ;
try {
PrintWriter out = response.getWriter();
out.println("<html ><head><title>Reference Check Results</title></head><bod y >");
searchParam = (Vector) input.readObject();
tableName= (String) searchParam.get(0);
primaryCol = (String) searchParam.get(1);
primaryKey = (String) searchParam.get(2);
out.println(getRecords(tab leName,pri maryCol,pr imaryKey)) ;
out.println("</body></html >");
out.close();
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
}
}
The following doGet method is giving me problems.
If I comment out the statements:
ObjectInputStream input=new ObjectInputStream(request.
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.
/**
* Sets the content type
*/
response.setContentType("t
try {
PrintWriter out = response.getWriter();
out.println("<html ><head><title>Reference Check Results</title></head><bod
searchParam = (Vector) input.readObject();
tableName= (String) searchParam.get(0);
primaryCol = (String) searchParam.get(1);
primaryKey = (String) searchParam.get(2);
out.println(getRecords(tab
out.println("</body></html
out.close();
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
}
}
ASKER
22-Mar-2006 21:12:28 org.apache.catalina.core.S tandardWra pperValve invoke
WARNING: Servlet.service() for servlet checkServlet threw exception
java.io.EOFException
at java.io.ObjectInputStream$ PeekInputS tream.read Fully(Obje ctInputStr eam.java:2 232)
at java.io.ObjectInputStream$ BlockDataI nputStream .readShort (ObjectInp utStream.j ava:2698)
at java.io.ObjectInputStream. readStream Header(Obj ectInputSt ream.java: 750)
at java.io.ObjectInputStream. <init>(Obj ectInputSt ream.java: 268)
at checkServlet.doGet(checkSe rvlet.java :46)
at javax.servlet.http.HttpSer vlet.servi ce(HttpSer vlet.java: 689)
at javax.servlet.http.HttpSer vlet.servi ce(HttpSer vlet.java: 802)
at org.apache.catalina.core.A pplication FilterChai n.internal DoFilter(A pplication FilterChai n.java:252 )
at org.apache.catalina.core.A pplication FilterChai n.doFilter (Applicati onFilterCh ain.java:1 73)
at org.netbeans.modules.web.m onitor.ser ver.Monito rFilter.do Filter(Mon itorFilter .java:362)
at org.apache.catalina.core.A pplication FilterChai n.internal DoFilter(A pplication FilterChai n.java:202 )
at org.apache.catalina.core.A pplication FilterChai n.doFilter (Applicati onFilterCh ain.java:1 73)
at org.apache.catalina.core.S tandardWra pperValve. invoke(Sta ndardWrapp erValve.ja va:213)
at org.apache.catalina.core.S tandardCon textValve. invoke(Sta ndardConte xtValve.ja va:178)
at org.apache.catalina.core.S tandardHos tValve.inv oke(Standa rdHostValv e.java:126 )
at org.apache.catalina.valves .ErrorRepo rtValve.in voke(Error ReportValv e.java:105 )
at org.apache.catalina.core.S tandardEng ineValve.i nvoke(Stan dardEngine Valve.java :107)
at org.apache.catalina.connec tor.Coyote Adapter.se rvice(Coyo teAdapter. java:148)
at org.apache.coyote.http11.H ttp11Proce ssor.proce ss(Http11P rocessor.j ava:856)
at org.apache.coyote.http11.H ttp11Proto col$Http11 Connection Handler.pr ocessConne ction(Http 11Protocol .java:744)
at org.apache.tomcat.util.net .PoolTcpEn dpoint.pro cessSocket (PoolTcpEn dpoint.jav a:527)
at org.apache.tomcat.util.net .LeaderFol lowerWorke rThread.ru nIt(Leader FollowerWo rkerThread .java:80)
at org.apache.tomcat.util.thr eads.Threa dPool$Cont rolRunnabl e.run(Thre adPool.jav a:684)
at java.lang.Thread.run(Threa d.java:595 )
WARNING: Servlet.service() for servlet checkServlet threw exception
java.io.EOFException
at java.io.ObjectInputStream$
at java.io.ObjectInputStream$
at java.io.ObjectInputStream.
at java.io.ObjectInputStream.
at checkServlet.doGet(checkSe
at javax.servlet.http.HttpSer
at javax.servlet.http.HttpSer
at org.apache.catalina.core.A
at org.apache.catalina.core.A
at org.netbeans.modules.web.m
at org.apache.catalina.core.A
at org.apache.catalina.core.A
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.core.S
at org.apache.catalina.valves
at org.apache.catalina.core.S
at org.apache.catalina.connec
at org.apache.coyote.http11.H
at org.apache.coyote.http11.H
at org.apache.tomcat.util.net
at org.apache.tomcat.util.net
at org.apache.tomcat.util.thr
at java.lang.Thread.run(Threa
looks like it is not an object stream.
If its not an object stream you can't use it with an ObjectInputStream
If its not an object stream you can't use it with an ObjectInputStream
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.setUseCa ches(false );
// Enable I/O through the connection
servletConnection.setDoInp ut(true);
servletConnection.setDoOut put(true);
ObjectOutputStream output = new ObjectOutputStream(servlet Connection .getOutput Stream());
// 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.";
}
}
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.setUseCa
// Enable I/O through the connection
servletConnection.setDoInp
servletConnection.setDoOut
ObjectOutputStream output = new ObjectOutputStream(servlet
// 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?
whats this do?
ASKER
This creates a jEditorPane which displays the html result from the servlet,
It uses the servlet address as you've guessed by now.
It uses the servlet address as you've guessed by now.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yes,
Pls see below:
ObjectOutputStream output = new ObjectOutputStream(servlet Connection .getOutput Stream());
// 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();
Pls see below:
ObjectOutputStream output = new ObjectOutputStream(servlet
// 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?
ASKER
>what else is in in searchPopup()'s constructor?
public searchPopUp(String title,URL hlpURL) {
super(title);
helpURL = hlpURL;
editorpane = new JEditorPane();
editorpane.setEditable(fal
try {
editorpane.setContentType(
editorpane.setPage(helpURL
}
catch (Exception ex) {
ex.printStackTrace();
}
//anonymous inner listener
editorpane.addHyperlinkLis
public void hyperlinkUpdate(HyperlinkE
try {
if (ev.getEventType() == HyperlinkEvent.EventType.A
editorpane.setPage(ev.getU
}
} catch (IOException ex) {
//put message in window
ex.printStackTrace();
}
}
});
getContentPane().add(new JScrollPane(editorpane));
addButtons();
// no need for listener just dispose
setDefaultCloseOperation(D
// 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
First "rebuild" the servlet - THEN "rebuild" the applet.
See if that fixes the problem.
cheers,
Leo
ASKER
>First "rebuild" the servlet - THEN "rebuild" the applet.
Tried it but it gives the same error stack trace
Tried it but it gives the same error stack trace
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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("t ext/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,
I did suspect that.
I tried this:
got rid of
response.setContentType("t
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
Happy programming.
Leo
________
radarsh