JSP Response getStatus

JSP Response getStatus


Posted in : Java Posted on : May 15, 2012 at 12:02 PM Comments : [ 0 ]

In this tutorial you will learn about the getStatus() method of response object in JSP.

JSP Response getStatus

In this tutorial you will learn about the getStatus() method of response object in JSP.

getStatus() method of response object is referred to HttpServletResponse interface. This method returns an integer value as a Status code of the status that has been set.

Syntax :

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page import="java.net.URL, java.util.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>JSP Response getStatus</title>
</head>
<body>
<form>
<table>
<tr>
<td>Enter website's name only : <br>
(e.g. devmanuals, google)</td>
<td><input type="text" name="webAdd"/></td>
</tr>
<tr>
<td>Enter domain of website : <br>
(like com, net, in)</td>
<td><input type="text" name="domain"/></td>
</tr>
<tr>
<td></td><td><input type="submit" value="submit"/></td>
</tr>
</table>
</form>
<%
String webAddress = request.getParameter("webAdd");
String dom = request.getParameter("domain");
URL newUrl = new URL("http://"+webAddress+"."+dom);
String url = newUrl.toString();
if(webAddress != null)
{
// setting status
response.setStatus(response.SC_MOVED_TEMPORARILY); 
// getting status
int i = response.getStatus();
out.println("Status is : "+i);
}
%> 
</body>
</html>

Output :

When you will execute the above JSP page you will get the output as follows :

1. At first the page will displayed to you for entering the value :

2. When you will enter the value like above and will click on submit button then the output will be as follows :

An output status 302 specifies the HttpServletResponse SC__MOVED_TEMPORARILY value.

Download Source Code

Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics