Embedding java codes in jsp sciptlets

By: aathishankaran Printer Friendly Format    

Embedding java codes in jsp sciptlets

             We can embed the java codes inside the jsp sciptlets. We can use the java variables like request, response, and session variable etc. by using the java variables we can create the dynamic WebPages through this we can get inputs and process such inputs and give the outputs

 Syntax of JSP Scriptles are:

  //java codes

JSP Scriptlets begins with <% and ends %> .We can embed any amount of java code in the JSP Scriptlets. JSP Engine places these code in the _jspService() method. Variables available to the JSP Scriptlets are:

  • request:
    request represents the clients request and is a subclass of HttpServletRequest. Use this variable to retrieve the data submitted along the request.

  //java codes
   String userName=null;

  • response:
    response is subclass of HttpServletResponse.
  • session:
    session represents the HTTP session object associated with the request.
  • out:
    out is an object of output stream and is used to send any output to the client.

Other variable available to the scriptlets are pageContext, application,config and exception.

The java expression can be expressed as follows


Syntax of JSP Expressions are:


  <%= …   %>


JSP Expressions start with 


Syntax of JSP Scriptles are with <%= and ends with  %>. Between these this you can put anything and that will convert to the String and that will be displayed.



  <%="Hello World!" %>

Above code will display 'Hello World!'.

Most Viewed Articles (in JSP )

Latest Articles (in JSP)

Comment on this tutorial