JSP (Java) sending HttpRequest and receiving HttpResponse

JSP (Java) sending HttpRequest and receiving HttpResponse

Sending response:
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

try{
response.getOutputStream().write(“<reply>1</reply>”.getBytes());
}
catch(Exception e){e.printStackTrace();}

Reading:
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class TtPaymentCheck extends Action  {

public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
{
String xForward=request.getHeader(“X-Forwarded-For”);
String via=request.getHeader(“Via”);
String remoteAddress=request.getRemoteAddr();
String applicationSN=request.getParameter(“applicationSN”);
try
{
URL url = new URL(“http://IP:PORT/kuetfromteletalk.php?user=&password=&appl_serial=”+applicationSN);
URLConnection uc = url.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(uc.getInputStream()));
String inputLine;
String inputLine1=””;
while ((inputLine = in.readLine()) != null)
{
System.out.println(inputLine);
if(inputLine!=null)
inputLine1+=inputLine;
}
in.close();
if(inputLine1!=null && !inputLine1.equalsIgnoreCase(“<reply>0</reply>”))
{
String[] tmp1 = inputLine1.split(“\\|”);
String[] tmp2 = tmp1[0].split(“>”);
tmp1[0] = tmp2[1];
}
try {response.getWriter().write(inputLine1);}
catch (Exception e) {e.printStackTrace();}
}
catch(Exception e)
{
e.printStackTrace();
}
return null;
}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s