I want to save pdf file to server from applet and for that i make one sevlet and request form applet , but request is not goes to perticular servlet from applet.and execute completly without any error
I have one sevlet TestDataHandler sevlet and
i called that sevlet from URL class, but request is not goes to from applet
code is here
applet code
public void action(final ViewerEvent event) {
try{
System.out.println("Save.action method call 1");
final PDF pdf = event.getPDF();
//final Exporter[] chosenexporter = new Exporter[1];
Exporter ex = new PDFExporter();
System.out.println("Save.action method call 2");
final DocumentPanel docpanel = event.getDocumentPanel();
final PDFViewer viewer = event.getViewer();
final JComponent secondarycomp = null;
System.out.println("Save.action method call 3");
String strURL ="http://127.0.0.1:8080/test/TestDataHandler"; //
URL serverUrl = new URL(strURL);
//System.out.println("serverurl..."+serverUrl.getFile().getBytes());
System.out.println("Save.action method call 4");
URLConnection dataHandlerConnection = serverUrl.openConnection();
System.out.println("Save.action method call 5");
dataHandlerConnection.setDoOutput(true);
System.out.println("Save.action method call 6");
// dataHandlerConnection.connect();
OutputStream out = dataHandlerConnection.getOutputStream();
DataOutputStream dos = new DataOutputStream(out);
//dos.write("This is
test input".getBytes());
dos.writeBytes("This is test input");
//out.write("This is test input".getBytes());
dos.flush();
dos.close();
//System.out.println("Exporter is : " + chosenexporter[0]);
// System.out.println("docpanel is : " + docpanel);
// Exporter.ExporterTask task = ex.getExporter(docpanel, docpanel.getPDF(), secondarycomp, out);
// System.out.println("Save.action method call 7");
// task.start(viewer, Util.getUIString("PDFViewer.SavingFile", "test file"));
System.out.println("Save.action method call 8");
}catch (Exception e) {
System.out.println("Exception while shaving data in Save.action()");
e.printStackTrace();
}
}
sevlet code
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
try{
System.out.println("Do GET method is called");
resp.setContentType("text/html");
InputStream is = req.getInputStream();
byte[] b = new byte[1024];
while(is.read(b)!=-1){
System.out.println("read byte :" + b.toString());
}
String contentType = req.getContentType();
System.out.println("Content type is :: " +contentType);
DataInputStream in = new DataInputStream(req.getInputStream());
int formDataLength = req.getContentLength();
byte dataBytes[] = new byte[formDataLength];
int byteRead = 0;
int totalBytesRead = 0;
while (totalBytesRead < formDataLength) {
byteRead = in.read(dataBytes, totalBytesRead, formDataLength);
totalBytesRead += byteRead;
}
System.out.println("read byte :" + dataBytes.toString());
System.out.println("Do GET method is over");
//resp.getWriter().println("DataHandlerServlet doGet is called");
}catch (Exception e) {
e.printStackTrace();
}
}