Win a copy of Functional Reactive Programming this week in the Other Languages forum!
    Bookmark Topic Watch Topic
  • New Topic

sending image file from applet to servlet

 
A Bhat
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Report post to moderator
I have seen several posts in this forum and couldn't find out that whether am supposed to send serialised object,multipart stream or octet stream as content type when transferring image from applet to servlet.I have done this applet to servlet variable value transfer.But while transferring images am not at all getting a clue.I need the image file to be in fileformat at the server's end.
This what is my code for sending a variable(password) content to servlet from applet.Can you tell what are the changes in code i shall do for sending image file to servlet from applet??

try {
// get input data for sending
String input = pass.getText();

// send data to the servlet
URLConnection con = getServletConnection();
OutputStream outstream = con.getOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(outstream);
oos.writeObject(input);
oos.flush();
oos.close();

// receive result from servlet
InputStream instr = con.getInputStream();
ObjectInputStream inputFromServlet = new ObjectInputStream(instr);
String result = (String) inputFromServlet.readObject();
inputFromServlet.close();
instr.close();

// show result
//JOptionPane.showMessageDialog(aComponent,result);
if (result.equalsIgnoreCase("You are wrong try again")) {
jLabel11.setText(result);

} else {
// jLabel11.setText(result);
givedetails();
}


} catch (Exception ex) {
ex.printStackTrace();
}


//THIS IS THE FUNCTION THAT I USED ABOVE FOR CONNECTION
private URLConnection getServletConnection()
throws MalformedURLException, IOException {


URL urlServlet = new URL(getCodeBase(), "APP");
URLConnection con = urlServlet.openConnection();


con.setDoInput(true);
con.setDoOutput(true);
con.setUseCaches(false);
con.setRequestProperty(
"Content-Type",
"application/x-java-serialized-object");

// und zur├╝ckliefern
return con;
}
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65218
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please do not cross-post the same question in multiple forums. It wastes people's time when multiple redundant conversations take place. Please read this for more information.
 
    Bookmark Topic Watch Topic
  • New Topic