Saturday, 14 March 2015

jsp import attribute


import attribute
the value is like import statement in java language.

Syntax
<%@ page import="memeber1,member2,...,memberN" %>

here member can be any package or any class. These members can be converted to import statements in servlet.

Example
<%@page import="java.util.Random, java.io.*" %>

Above page directive imports Random class and io package. Observe that there is no semi colon after importing classes and packages.

<%@page language="java" contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.util.Random, java.io.*" %>

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Hello World</title>
    </head>
    <body>
        <h1> 
            <%
                Random rand = new Random();
                int randVal = rand.nextInt();
            %>
            
            Random vale is :<%=randVal%>
        </h1>
        
    </body>
</html>
 
Sample Output
 
Below packages import into JSP page by default.

java.lang
javax.servlet
javax.servlet.http
javax.servlet.jsp


Prevoius                                                 Next                                                 Home

No comments:

Post a Comment