Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

How to download a page from a web server?

  Asked By: Elliott    Date: Jun 29    Category: Java    Views: 501
  

Anyone who knows how to do this using Java. Which Java class(es)
could I use?

Share: 

 

5 Answers Found

 
Answer #1    Answered By: Skye Hughes     Answered On: Jun 29

I am sending the code what i had used for downloading the file from the
server.we will be using the hastable and store the downloable data.

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import ServletUtils;
import java.util.*;

public class down extends HttpServlet {

String str="";
public void init(ServletConfig config) throws ServletException{
super.init(config);
}

public void download(String myfilename,String filename,HttpServletResponse
res,HttpServletRequest req)
throws ServletException, IOException{
HttpSession session = req.getSession(true);
String strUserId = (String)(session.getValue("userid"));
String strBrowser = new String("");
String strDomain = (String)(session.getValue("userdomain"));
String strSetting = (String)(session.getValue("usersetting"));

if (req.getHeader("User-Agent").toUpperCase().indexOf("MSIE") == -1)
strBrowser="NN";
else
strBrowser="IE";
if(strBrowser.equals("NN"))
{
res.setContentType("application/octet-stream; name="+filename+"");
res.setHeader("Content-Disposition","attachment; filename=\"" + filename +
"\";");
}

else if(strBrowser.equals("IE"))
{ res.setContentType("application/x-filler");
res.setHeader("Content-Disposition","attachment; filename=\"" + filename +
"\";");
}

System.out.println("filename isn download  is "+filename);
ServletOutputStream out=res.getOutputStream();
try{
ServletUtils.returnFile(myfilename,out);

}
catch(FileNotFoundException fnfe){System.out.println("fileNot
Found+_+_+>"+fnfe);}
out.flush();
out.close();
}
public String downloadAmtFormat(String strAmt)
{
String Amount="";
if((strAmt==null) || (strAmt.equals("")))
Amount="\t";
else
{
StringTokenizer st=new StringTokenizer(strAmt,",");
while(st.hasMoreElements())
Amount+=st.nextElement();
Amount+="\t";
}
return Amount;
}
}

 
Answer #2    Answered By: Funsani Chalthoum     Answered On: Jun 29

Do I really need to employ servlet technology?

Maybe I am not clear with what I want. I want to write a client
application (in Java). The application reads a page  (with url) from a
web site. The return page or data is then analysed.

With VB, I think I could use Winsock. Now I don't want VB but Java.
Instead of winsock, what could I take in Java?

 
Answer #3    Answered By: Randall Franklin     Answered On: Jun 29

I think you should use servlet anyway.
The interaction will be via InputStream and OutputStream or
ObjectInputStream and ObjectOutputStream

From java  application:
java.net.URL Url=new java.net.URL(S_URL);
java.net.URLConnection UrlConn=Url.openConnection();
java.io.OutputStream os=UrlConn.getOutputStream();
java.io.InputStream is=UrlConn.getInputStream();

From Servlet:
ObjectInputStream ois = new ObjectInputStream(request.getInputStream
());
ObjectOutputStream oos = new ObjectOutputStream
(response.getOutputStream());

You can get and post any data from and to servlet this way

 
Answer #4    Answered By: Josie Roberts     Answered On: Jun 29

You can use the URL class...............

 
Answer #5    Answered By: Marc Anderson     Answered On: Jun 29

I'm using the httpClient package I found on www.inovation.ch it a very good
package. It
handles cookies en redirects. You can even log in when the site uses standard
login. The
only problem i'm still facing is how do I process the javascript code on the
page. I'm
trying to write a program that login in to the yahoo groups and creates them on
my pc,
makes a copy of the latest files, photos and messages.

 
Didn't find what you were looking for? Find more on How to download a page from a web server? Or get search suggestion and latest updates.




Tagged: