Embedding java codes in jsp sciptlets

By: aathishankaran Emailed: 1615 times Printed: 2077 times    

Latest comments
By: rohit kumar - how this program is work
By: Kirti - Hi..thx for the hadoop in
By: Spijker - I have altered the code a
By: ali mohammed - why we use the java in ne
By: ali mohammed - why we use the java in ne
By: mizhelle - when I exported the data
By: raul - no output as well, i'm ge
By: Rajesh - thanx very much...
By: Suindu De - Suppose we are executing

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.

Example:
  <%
  //java codes
   String userName=null;
   userName=request.getParameter("userName");
   %>

  • 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.

 

Example:

  <%="Hello World!" %>

Above code will display 'Hello World!'.


JSP Home | All JSP Tutorials | Latest JSP Tutorials

Sponsored Links

If this tutorial doesn't answer your question, or you have a specific question, just ask an expert here. Post your question to get a direct answer.



Bookmark and Share

Comments(0)


Be the first one to add a comment

Your name (required):


Your email(required, will not be shown to the public):


Your sites URL (optional):


Your comments:



More Tutorials by aathishankaran
Web Security Issues
The Web User's Perspective
Server-side plug-Ins
The best way to avoid security vulnerabilities with new server
JavaScript Security
Window Object
Working with Status Bar Messages
Retrieving a Portion of a String
Referencing Windows
Math Object
Frame Object
Document Object
Closing Windows
Built-in Object in Javascript
Textarea Object

More Tutorials in JSP
LifecycleException: service.getName(): "Catalina"; Protocol handler start failed: `java.net.BindException: Permission denied <null>:80
JSP Alert Example
JSP CheckBox Example
Uploading an Image to a Database using JSP
Uploading a file to a server using JSP
A JSP page that gets properties from a bean
The page Directive in JSP
The taglib, tag, include, attribute and the variable Directive in JSP
Declarations in JSP
Scriptlets and Expressions in JSP
Tag Libraries in JSP
The Request Object in JSP
The Response Object in JSP
The Out Object in JSP
The Session Object in JSP

More Latest News
Most Viewed Articles (in JSP )
JSP Example to connect to MS SQL database and retrieve records
JSP Alert Example
What are the different scopes in JSP?
JSP CheckBox Example
JSP Program for display Date
Uploading a file to a server using JSP
Embedding java codes in jsp sciptlets
Sending Email using JSP
Writing your first JSP page
Arithmetic Evaluation Using the Expression Language in JSP
Sessions in JSP
Packaging Servlets
The Advantages of JSP
Automatically Refreshing a JSP
The page Directive in JSP
Most Emailed Articles (in JSP)
Embedding java codes in jsp sciptlets
Packaging Servlets
What are the different scopes in JSP?
A JSP page that gets properties from a bean
The Advantages of JSP
The taglib, tag, include, attribute and the variable Directive in JSP
Sessions in JSP
Retrieving a Portion of a String
Server-side plug-Ins
The Advantages of Servlets Over “Traditional” CGI
Enable/Disable Scripting Elements in JSP
Scriptlets and Expressions in JSP
The Response Object in JSP
Uploading a file to a server using JSP
JSP Alert Example