/**
* Front-end Ajax get management relative latitude information
* @author Jiyanle
* @date 2014-10-31
*/
Public String getPosition () {
HttpServletResponse response = Servletactioncontext.getresponse ();
String jsonstr = "";
PrintWriter out = null;
BufferedReader in = null;
try {
String param = "compno=341421110525083290®ioncode=340000";
URL url = new URL ("Http://gis.wsjd.gov.cn:8080/Weisheng/placeinfo/getPlacesAction.action?") +param);
URLConnection conn = Url.openconnection ();
Conn.setusecaches (TRUE);
The following two lines must be set for sending a POST request;
Conn.setdooutput (TRUE);
Conn.setdoinput (TRUE);
Conn.setrequestproperty ("Content-type", "Application/octest-stream");
Gets the output stream corresponding to the URLConnection object
out = new PrintWriter (Conn.getoutputstream ());
Send Request parameters
Out.print (param);
Buffer for flush output stream
Out.flush ();
Defines the response of the BufferedReader input stream to read the URL
in = new BufferedReader (New InputStreamReader (Conn.getinputstream ()));
Jsonstr = In.readline ();
Ajax return value
out = Response.getwriter ();
Out.print (JSONSTR);
}
catch (Exception e) {
E.printstacktrace ();
}
Use the finally block to close the output stream, input stream
finally {
try {
if (out! = null)
{
Out.close ();
}
if (in = null)
{
In.close ();
}
}catch (Exception e) {
E.printstacktrace ();
}
}
return null;
}
Java Call (Request) remote service address