wellnwill

JSP

Declarations

  • Methods definitions, blocks, constructors, class level variable are allowed inside declaration tags
  • All code inside the declaration will be placed directly inside the translated servlet class and outside the _jspService() method

Syntax

<%!
//global var
//methods
}
%>

Example

<%!
String name = “Atul”;
void myMethod(){
...
}
%>

After translation _jspService()

public class welcome_jsp extends HttpServlet {
String name = “Atul”;
void myMethod(){
...
}
public void init(ServletConfig config) 
                 throws ServletException {}
public void destroy(){}
protected void service(HttpServletRequest request,
                       HttpServletResponse response) 
                       throws ServletException, IOException {
PageContext pageContext = null;
HttpSession session = null
ServletContext application = null;
ServletConfig config = null;
JspWriter out = null;
Object page = null;
...
out.write(“My Heading”);
...
int i = 10;
out.print(i);
System.out.println(i);
...
        }
}
Footer with Map

Top