Implicit Object in JSP, out Object in JSP, What is the Use of out Object in JSP

Implicit Object in JSP, out Object in JSP, What is the Use of out Object in JSP

out is the object of JspWriter class in JSP, it is similar to the PrintWriter class in JSP. It is used to print any string on the browser or client as a response.

Example for out Object:-


login.html
<html>
<head><title>Login Here</title></head>
<form method="post" action="loginValidate.jsp">
<input type="text" name="user"><br>
<input type="password" name="pass"><br>
<input type="submit" value="login">
</form>
</html>

loginValidate.jsp

<%
if(request.getParameter("user").equals("admin")&&request.getParameter("pass").equals("admin"))
{
out.write("Hello "+request.getParameter("user"));
}
out.write();

%>

Thanks for Visiting

Learn more »

Implicit objects in JSP, list of Implicit Objects in JSP, JSP Implicit Objects

Implicit objects in JSP, list of Implicit Objects in JSP, JSP Implicit Objects

The JSP provide the 9 implicit Objects for doing any specific task in JSP, these all objects has the unique meaning and each is given the facility to invoke the methods defined into the its class like the session is the object of HttpSession interfce, out is the object of PrintWriter class etc, all the methods has the power of invoking the all methods and properties of its Class or Interface.

Here is a List of 9 implicit objects provided by JSP:-

out:- out is the object of JspWrite class which is similar to the PrintWriter class which we have used in Servlets which is used to print any value on the browser.
request:- request is the object of HttpServletRequest interface which is used to get the request from the client.
response:- response is the object of HttpServletResponse interface which is used to set the response for the client.
config:- config is the object of Servlet config interface, it is used to get the configuration for a JSP page from a web.xml file. It is used to get info for a single jsp page.
application:- application is the object of ServletContext interface, it is used to get the configuration information from the web.xml file. It can be used to get info for all jsp pages of an application.
session:- session is the object of HttpSession interface, it is used to create , set, get and destroy the session variables.
pageContext:- pageContext is the object of pageContext class. It is used to store any value which can be available by the page, request, session & application scopes to the other pages.
page:- page object is the object of Object class. It is used to assign the current class reference.
exception:- exception is the object of Throwable class. It is used in error page of a JSP application.

If you want to know more about the implicit objects then visit the next tutorials of this site.

Thanks for visiting
Learn more »

Taglib Directive in JSP, How to use Taglib Directive in JSP, What is the use of Taglib Directive in JSP

Taglib Directive in JSP, How to use Taglib Directive in JSP, What is the use of Taglib Directive in JSP

The taglib directory is used to define the many tags means the taglib is used to create the custom tags in JSP and also use the predefined JSTL tags library into the JSP page for coding the JSP without using the scriptlet tag.

Syntax for using the taglib directive:-

<%@ taglib prefix="variable name" uri="url of tag library" %>

The more tutorials on depth about the taglib into next chapter.

Thanks for visiting


Learn more »

Include Directive in JSP, What is the use of include directive in JSP, How to include a file into a JSP page

Include Directive in JSP, What is the use of include directive in JSP, How to include a file into a JSP page

The include directive is used to include an external page or file of any type like any HTML page, any JSP page, any image file, any text file, xml file etc into the JSP page, The include directive include the page or file into the translation time of a JSP page. you can write the include directive code anywhere into the page wherever you want.

Syntax of the include directive

<%@include file="filename"%>

Example:-

<%@include file="header.html"%>
<html>
<head><title>Welcome Page</title></head>
<body>
</body>
</html>
<%@include file="footer.html"%>

Thanks for visiting
Learn more »

Page Directive in JSP, Attributes of @ Page Directive in JSP, Use of Page Directive in JSP

Page Directive in JSP, Attributes of @ Page Directive in JSP, Use of Page Directive in JSP

Page Directive is used to specify the JSP page info to the Web Container like page language, page will participate in sessions or not, you can specify the API' list which are import to your JSP page, the Page directive can be placed anywhere into the JSP page but the best practice is to write it top of the page.

Syntax of Page Directive

<%@ page attribute="value"%>

List of Page Directive Attributes

language:- This attribute is used to specify the default language for the JSP page.
session:- The session attribute used to specify whether the page participate in session or not, the value for the session attribute can be true or false.
extends:- This attribute specify the super class used by the JSP page.
import:- This attribute specify the list of API's included into the JSP page.
isErrorPage:- This attribute specify the page is the error page URL or not by specify into the another JSP errorPage attribute.
errorPage:- This attribute used to specify the URL of the error handler page.
contentType:- This attribute is used to specify the content type of the particular JSP page.
isThreadSafe:- This attribute specify the threading model used by the JSP page. the default value for this attribute is true, if you set it false then the Container will serialize the multiple requests and the servlet uses the SingleThreadModel for it.
isELIgnored:- This attribute specify the Expression Language ignored by the JSP page or not. By default the Expression language is enabled by the JSP page. It means the value is false by default.
info:- This attribute is simply used to specify the information for the JSP page which is retrieved by the getServletInfo() method later.

Example of the Page Directive

<%page language="java" import="java.io.*" session="true" isErrorPage="false" info="This is the JSP Example" %>

thanks for visiting
Learn more »

JSP Directives Tags, What are the JSP Directives in JSP

JSP Directives Tags, What are the JSP Directives in ,JSP

JSP Directives are used to specify what will be the structure of the JSP page, the directives tags can be used to specify the language used by the JSP page, the page will participate in sessions or not, if you want to include any existing page into your JSP page, the Directives also useful, if you want to create the database connection which you want to use into the entire application then the JSP directives also useful.

There are three type of JSP directives available in JSP.


  1. <%@page %>
  2. <%@include %>
  3. <%@taglib %>
we will discuss about the above tags in depth in next tutorials

thanks for visiting
Learn more »

JSP Expression Tag, How to Print Value of any Variable without out.write() in JSP, How to call a method in JSP

JSP Expression Tag, How to Print Value of any Variable without out.write() in JSP, How to call a method in JSP

If you want to print the value of any variable in JSP so you can simply use the out.write(variablename) inside the scriptlet tag but, if you dont want to use scriptlet and don't want to use the out.write() method then, the JSP also provide a special tag for doing this task, you can print the value of any variable without using out.write() method, this tag called the Expression Tag, with the help of this tag you can easily call a method too.

Syntax of Expression Tag

<%= expression %>

Example of Expression Tag

<html>
<head>
<title>Handling Request</title>
</head>
<body>

<%! String username="";%><%
String user=request.getParameter("user");

String pass=request.getParameter("pass");
if(user.equlas("admin")&&pass.equals("admin"))
{
username=user;
}%>
<h1>Welcome <%= username %></h1></body>
</html>


Thanks for visiting
Learn more »

Scriptlet Tag in JSP, How to write Java Code in JSP, JSP Scriptlet Tag for Writing Java Codes inside the HTML

Scriptlet Tag in JSP, How to write Java Code in JSP, JSP Scriptlet Tag for Writing Java Codes inside the HTML

The JSP Code can be embed with HTML and every Java Code written inside the JSP Tags. The Scriptlet Tag is one of the Tags which is used to write the Java Code inside the HTML code like if condtional statements, iterative statements, handle requests, sending response, the Scriptlet Tags are used to do these tasks.

The syntax for Scriptlet Tag

<%
//code here
%>

Example for Scriptlet Tag

<html>
<head>
<title>Handling Request</title>
</head>
<body>
<%
String user=request.getParameter("user");
if(user.equals("admin"))
{
response.sendRedirect("welcome.jsp");
}
%>
</body>
</html>

Thanks for visiting
Learn more »

Declaration Tag in JSP, What is the use of Declaration tag in JSP, How to Declare the global variable and methods in JSP

Declaration Tag in JSP, What is the use of Declaration tag in JSP, How to Declare variable and functions in JSP

The Declaration tag in JSP is used to to declare the variables and methods in JSP. If you want to declare the global variables in JSP the Declaration tag is used, the variables and methods which are declared into the Declaration tags are available in the entire JSP page and every scriptlets tag which is used into the JSP page.

The syntax for Declaration tag is follows:-

<%!
declare variables...
declare functions...
%>

The following example shows the declaration tag:-

<%!
int x,y,z;
public void sum(int x, int y);
%>

Thanks for visiting
Learn more »

Tags in JSP, JSP Tags, How many tags available in JSP

Tags in JSP, JSP Tags, How many tags available in JSP

The JSP provide the four basic tags for working with java codes, these tags are work differently for doing the specific tasks into a JSP pages like if you want to declare variables and functions, the declaration tag is used and if you want to make logic like conditional statements, iterative statements etc, the scriptlet tag is used.

The four basic tags are as follows:-


  1. Declaration Tag.
  2. Scriptlets Tag.
  3. Expression Tag.
  4. Comment Tag.
We will discuss about all above tags in depth in next chapters.


Thanks for visiting
Learn more »