Object | Availability and Uses |
---|---|
Request | The javax.servlet.http.HttpServletRequest object is associated with the request. |
Response | The javax.servlet.http.HttpServletResponse object is associated with the response. |
Out | The javax.servlet.jsp.JspWriter object is used to send output the client. |
Session | The javax.servlet.http.HttpSession object is associated with the session for the given client request. |
Application | The javax.servlet.ServletContext object is used for the web application. |
Config | The javax.servlet.ServletConfig object is associated with the Servlet for current JSP page. |
pageContext | The javax.servlet.jsp.PageContext object encapsulates the environment of a single request for the current JSP page. |
Page | The page variable is similar to this variable of Java programming. It is available in java.lang.Object class. |
Exception | The Exception object represents the Throwable object that was thrown by some other JSP page. |
//welcome.html
<html>
<head>
<title>Username & Password</title>
</head>
<body>
<form action="welcome.jsp">
Enter User Name: <input type="text" name="uname" /> <br>
Enter Password: <input type="text" name="pass" /> <br>
<input type="submit" value="Submit"/>
<input type = "submit" value = "Reset">
</form>
</body>
</html>
//welcome.jsp
<%@ page import = " java.util.* " %>
<html>
<body>
<%
String username = request.getParameter("uname");
String password = request.getParameter("pass");
out.print("Welcome: "+username);
%>
</body>
</html>
//index.html
<html>
<body>
<form action="session.jsp">
<input type="text" name="uname">
<input type="submit" value="Click here!"><br/>
</form>
</body>
</html>
//session.jsp
<html>
<head>
<title>Passing Session Variables</title>
</head>
<body>
<%
String name = request.getParameter("uname");
out.print("Welcome "+name);
session.setAttribute("user",name);
<a href="display.jsp">Display Page</a>
%>
</body>
</html>
//display.jsp
<html>
<body>
<%
String name=(String)session.getAttribute("user");
out.print("Welcome "+name);
%>
</body>
</html>
//welcome.html
<form action="welcome.jsp">
<input type="text" name="uname">
<input type="submit" value="Click here!!"><br/>
</form>
//web.xml
<web-app>
<servlet>
<servlet-name>TutorialRide</servlet-name>
<jsp-file>/welcome.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>TutorialRide</servlet-name>
<url-pattern>/test</url-pattern>
</servlet-mapping>
</web-app>
//welcome.jsp
<html>
<head>
<title>Config Implicit Object</title>
</head>
<body>
<%
String sname = config.getServletName();
out.print("Servlet Name: "+sname);
String
%>
</body>
</html>