• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Openconnection ,readobject,writeobject,errors,quesition

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi I have big problem.
I wrote the little program .this program communicated via object to servlet.
This application(client) make a serilazable object and send to servlet ,after the servlet send back to the application .
I try it servlet ,and jsp under jswdk1.0.1 version .
This program never work on jsp, because of servlet sided request.getInputStream is null- why??
Another problem this client communicated to servlet .
I wrote program�s two version an old and a new version,but the servlet communicated code part is the same.
So, the old version program is work ,and new version is not work ,whit servlet.
The application (client side code) new version.(method )
//The global variables;
public String ServerUrlString="http://localhost:8080/rejtveny/servlet/RejtvenyServlet";
//public String //ServerUrlString="http://localhost:8080/rejtveny/jsp/RejtvenyServletJsp.jsp";

private ObjectOutputStream out;
private URLConnection ServerConnection;
private URL ServerUrl;
public Objectum FileObject;
public void Send_Request_To_Server(String req,Object ob0,Object ob1) throws IOException{
try{
ServerUrl=new URL(this.ServerUrlString);
ServerConnection = ServerUrl.openConnection();
System.out.println("Received a : " + ServerConnection.getClass().getName());
this.ServerConnection.setDoOutput(true);
this.ServerConnection.setDoInput(true);
this.ServerConnection.setUseCaches(false);
this.ServerConnection.setDefaultRequestProperty("szega","hh");
this.ServerConnection.connect();
}catch(MalformedURLException i){}
//System.out.println(
out=new ObjectOutputStream(ServerConnection.getOutputStream()); //-here is break throws exception I-problems
FileObject=new Objectum(req,ob0,ob1);
System.out.print("ServerConnection1");
out.writeObject(FileObject);
out.flush();
try{
ObjectInputStream in=new ObjectInputStream(ServerConnection.getInputStream());
this.FileObject=(Objectum)in.readObject();
System.out.println("Response:"+this.FileObject.getType());
}catch (Exception s){
System.out.println("ClassNotFoundException");}
}//end Send Server

The old send server code = new send server code a different only global variables.
private ObjectOutputStream out;
private URLConnection ServerConnection;
private URL ServerUrl;
public Objectum FileObject;

the server side code:
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("begin"); //sometimes this execute
ObjectInputStream in= new ObjectInputStream(request.getInputStream()); //but here is frozen the jswdk
System.out.println("ObjectInputStream");
try{
reqObjectum=(Objectum)in.readObject();
in.close();
}catch (ClassNotFoundException e){}
this.objectGetType=this.reqObjectum.getType();
----if this.objectType---
//response
try{
String sss=�ok�;
Objectum Massage=new Objectum(sss,sss,sss);
ObjectOutputStream out=new ObjectOutputStream(response.getOutputStream());
out.writeObject(Message);
out.flush();
}catch(IOException e){}
}

--the objectum :
class Objectum implements Serializable{
Object ob0;
Object ob1;
String st;
public Objectum(String st,Object ob0,Object ob1){
this.ob0=ob0;
this.ob1=ob1;
this.st=st;
}
public void setObject0(Object ob0){
this.ob0=ob0;}
public void setObject1(Object ob1){
this.ob1=ob1;}
public void setType(String st){
this.st=st;}
public Object getObject0(){
return this.ob0;}
public Object getObject1(){
return this.ob1;}
public String getType(){
return this.st;}
}
the jsp code
<%@ page import="java.io.*" %>
<%@ page import="javax.servlet.*" %>
<HTML>
<HEAD>

<jsp:useBean id="my" scope="application" class="servlets.RejtvenyServlet" />
<%! ObjectInputStream inp=new ObjectInputStream(request.getInputStream()); %>
<%=inp.isEmpty().toString() %>
<%
InputStream ink= request.getInputStream();
out.println(ink.available());//-0 bytes writes
//v.getDate();
//Frame1();
my.processRequest(request,response); //this is another RejtvenyServlet class,which previous class
%>
<%=my.getValid() %>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1250">
<TITLE>
Hello World
</TITLE>
</HEAD>
<BODY>
<%="fdfddfg"%>
<H2>The following output is from JSP code:</H2><P><% out.println("Hello World"); %></P>
</BODY>
</HTML>

I think the problem on the client side at �I-problems�;
If you can help me write the szkrichard@freemail.hu thanks.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It makes no sense to use JSP to do any transmission of binary files such as a serialized object. JSP expects to work with character streams.
 
Do not threaten THIS beaver! Not even with this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic