Web Component to Web Component Communication
JSP
<jsp:include>
http://java.sun.com/products/jsp/syntax/1.2/syntaxref1214.html#8828
-include static content, OR content generated from another web component (URL) directly into a .jsp page. JSP continues to process the page after the content is inserted.
<jsp:forward>
http://java.sun.com/products/jsp/syntax/1.2/syntaxref1212.html#15694
-transfer control by forwarding a request to another web component (URL), the clients browser is redirected, but the request object information is forwarded.
java.net.*
httpUrlConnection (subclass of URLConnection)
getResponseCode: 200, 401,…
getResponseMessage: message associated with code
Working with URLs – Java Trail: http://java.sun.com/docs/books/tutorial/networking/urls/index.html
/**
* Acts
as a web client and fetches the HTML code from the given URL
*
* @Param URL
for HTTP request
*
* @Return HTML code or the virtual path
*/
private String getThatPage(String p_sUrl) throws
Exception
{
URL url = null;
InputStream isIn = null;
DataOutputStream dosOut;
String sOut = "";
StringBuffer
sUrlContent = new StringBuffer();
BufferedReader disIn;
try
{
url = new URL (p_sUrl);
isIn = url.openStream();
disIn = new BufferedReader(new
InputStreamReader(isIn));
while
((sOut = disIn.readLine())
!= null)
{
if
(sUrlContent.length() ==0)
{ // Url not
found
if
(sOut.indexOf("Error 404")> 0)
throw ( new
Exception("Error 404"));
}
sUrlContent.append("\n"
+ sOut);
}
disIn.close();
isIn.close();
}
catch
(Exception ex)
{
throw
ex;
}
finally
{
disIn = null;
isIn = null;
dosOut = null;
}
return sUrlContent.toString();
}
For
posting:
HttpURLConnection myHTTPConn = null;
myHttpConn = url.openConnection();
OutputStream os = myHttpConn.getOutputStream();
PrintWriter out = new PrintWriter(os);
while
out.write
}
out.close();
os.close();
status = myHTTPConn.getResponseCode();
message = myHttpConn.getResponseMessage();
if
(status >= HttpURLConnection.HTTP_OK) && (status
< HttpUrlConnection.HTTP_MULT_CHOICE)
{
read response
…