import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class Test
*/
public class BiopUrl extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("start ....");
String urlStr=request.getParameter("urlStr");
HttpURLConnection httpConn = null;
try
{
URL url = new URL(urlStr);
httpConn = (HttpURLConnection)url.openConnection();
httpConn.setUseCaches(false);
httpConn.setDoInput(true);
httpConn.connect();
BufferedInputStream bis = new BufferedInputStream(httpConn.getInputStream());
BufferedReader in = new BufferedReader(new InputStreamReader(bis));
StringBuffer respXML = new StringBuffer();
String line = null;
while ((line = in.readLine()) != null) {
respXML.append(line);
}
response.setCharacterEncoding("gbk");
response.getWriter().write(respXML.toString());
}
catch (Exception e)
{
}
finally
{
if (httpConn != null)
httpConn.disconnect();
}
System.out.println("end ....");
}
}