As we know that JAVA is a secure platform for any kind of software or web application development but without JSP web application development is quite tough in java. JSP i.e. JavaServer Pages is a server side technology which is having access to JDBC APIs to access or interact with database. It's similar to PHP and ASP, but only uses java programming language. Here we are going to explain the way to integrate java code in JSP pages which is quite easier by using java apis.
Step 01 : Create JSP Page
Initialy, we have to create a JSP page which will contain scriptlet. It will works like a block or widget which will execute java code in jsp page and return output as text to display according to our layout. In this scriptlet, we can define any numbers of java statements like variables, methods etc. to accessible in JSP pages. Now, we have created a file i.e. demo.jsp.
<%code fragment%>
File Name : demo.jsp
<html>
<head>
<title>Demo JSP Example - Etutorialz - A technical hub for all </title>
</head>
<body>
How to integrate Java Code in JSP page
</body>
Step 02 : Import Java packages
After creating a simple JSP file, we have to make it dynamic by calling java statements in scriptlet.
<%@ page import="java.util.Etuts"%>
<html>
<head>
<title>Demo JSP Example - Etutorialz - A technical hub for all </title>
</head>
<body>
<p>Etutorialz - How to integrate Java Code in JSP page</p>
<% System.out.println(); %>
<%
Etuts etusobj = new Etuts();
System.out.println("Custom Text: " + etusobj.getMyText());
%>
</body>
Step 03 : Ready to Execute
Now, you are ready to execute your jsp file through browser.
http://localhost:8080/etutorialz/demo.jsp