• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

HTTpClient text file upload to Server and open url to see the contents

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


hi ranchers,


i want to upload my text file through swing application to server(JSP page) through http client and postmenthod and i want to open the url(JSP page ) by click on button to see the text contents on server.


my swing applicatopn code looks like (where Http client and postmethod i used ):


String url = "http://localhost:8084/Test/index.jsp";
HttpClient client = new HttpClient();
PostMethod postMethod = new PostMethod(url);

try {

client.setConnectionTimeout(10000);
// Send any text file as the body of the POST request
File f = new File(jTextField1.getText()); // comes from text feild when user browse the text file to see on jsp page.
System.out.println("File Length = " + f.length());
postMethod.setRequestBody(new FileInputStream(f));
postMethod.setRequestHeader("Content-type", "text/plain; charset=ISO-8859-1");
int statusCode1 = client.executeMethod(postMethod);
System.out.println("status code" + statusCode1);
System.out.println("statusLine>>>" + postMethod.getStatusLine());
if (statusCode1 == 200) {
Process p = null;
try {
p = Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler http://localhost:8084/TestMireo/index.jsp"); // to open the url
p.waitFor();
} catch (Exception ex) {
}
}
} catch (Exception ex) {
ex.printStackTrace();
} finally {
//mPost.recycle();
//mPost.releaseConnection();
postMethod.releaseConnection();
}


my jsp page looks like :

<%@ page import="java.util.Scanner"%>
<%@ page import="java.io.PrintWriter"%>
<%@ page import="java.io.InputStreamReader"%>
<%@ page import="java.io.InputStream"%>
<%@ page import="java.io.IOException"%>
<%@ page import="java.io.BufferedReader"%>
<%@ page import="org.apache.commons.fileupload.DiskFileUpload"%>
<%@ page import="org.apache.commons.fileupload.FileItem"%>
<%@ page import="java.util.List"%>
<%@ page import="java.util.Iterator"%>
<%@ page import="java.io.File"%>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<script type="text/javascript" src="http://124.153.83.208/MapServer/MireoWebMap.js?redirect=mmi.mmiredirector.do"></script>
<script type="text/javascript" src="js/mmiFront.js" ></script>
<script type="text/javascript" src="js/Overlays.js" ></script>
<link href="images/styles.css" rel="stylesheet" type="text/css"/>
<link rel="stylesheet" type="text/css" href="images/csshorizontalmenu.css" />
<link href="css/color.css" rel="stylesheet" type="text/css"/>

</head>

<%

Scanner scanner = new Scanner(request.getInputStream());
String body=null;

StringBuffer sb = new StringBuffer();
if (scanner.hasNextLine()) {

String strLine;
int count = 0;
String spltarr[] = null;

sb.append("var resObj=new Object();var arr=new Array();");
sb.append("var step=null;var stepArr=new Array();");


while (scanner.hasNextLine()) {
strLine = scanner.nextLine();
count++;
spltarr = strLine.split(";");
sb.append("step = new Object();");
sb.append("step['lon']='");
sb.append(spltarr[1]);
sb.append("';step['lat']='");
sb.append(spltarr[2]);
sb.append("';stepArr.push(step);");
}
System.out.println("Count " + count);
sb.append("resObj['count']=");
sb.append(count);
sb.append(";resObj['steps']=stepArr;");

body =sb.toString();
System.out.println("Lat Lon : " + body);

}
%>

<body bgcolor="#f0e2da" onload="callfn('<%= body %>');"> i am not geting this body string in my java script .
Upload Successful!!
<iframe id="requestIframe" name="requestIframe" style="width:0px; height:0px; border:0px; visibility:hidden;" src="about:blank"></iframe>

<div id="map">
<div id="MapDiv" style="border:1px solid #999;width:790px;height:800px;">
</div>
</div>
</body>

</html>


my java script function is :


function callfn(body){

alert(body); not getting anything

};



my question is on jsp body load i am calling the funtion callfn but i an not getting anything into my java script . can you please help me to get the contents of my text file on java script.

[b]my text file contents are like :


1300710987;76.2936;27.8913;331;0;38;1
1300710988;76.2936;27.8913;331;0;38;1
1300711026;76.2937;27.8914;330;8;40;1
1300711031;76.2938;27.8914;330;6;46;1
1300711032;76.2938;27.8914;330;8;46;1
1300711040;76.2939;27.8916;330;5;40;1
1300711041;76.2939;27.8916;330;1;40;1
1300711050;76.2939;27.8916;330;10;30;1
1300711051;76.2939;27.8916;330;12;40;1
1300711052;76.294;27.8917;330;13;37;1
1300711055;76.294;27.8918;329;13;44;1
1300711056;76.2941;27.8918;330;15;45;1
1300711057;76.2941;27.8918;330;19;42;1
1300711058;76.2941;27.8918;330;21;42;1


thanks in advance


 
You're not going crazy. You're going sane in a crazy word. Find comfort in this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!