Hey guys in this article, you will learn about calling java method from JSP file with easy to understand example.
Read More:
- Check the Complete JSP Tutorials
- Check the Complete Spring Boot Tutorials [100+ Examples]
- Check the Complete Spring Boot and Thymeleaf Tutorial
- Check the Complete AWS Tutorial
- Check the Complete JavaServer Faces (JSF) Tutorial
- Check the Complete Spring Data JPA Tutorial
- Check the Complete Spring Security Tutorial
- Check the Javascript Projects for Beginners
- Check the Spring Boot JdbcTemplate Tutorials
Table of Contents
Complete Example
Follow the below steps to understand the complete example
Create a Project
You can check the following post to create a new Dynamic Web Project
Create a Java file
Create Test.java
inside src/in.bushansirgur
package and add the following content
package in.bushansirgur;
public class Test {
public static String convertToUpper(String text) {
return text.toUpperCase();
}
}
Create a JSP file
Create JSPTest.jsp
file under WebContent and add the following content
<%@page import="in.bushansirgur.Test"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<p>Converting the text to Upper case: <%= Test.convertToUpper("b2tech - web dev snippets") %> </p>
</body>
</html>
Run the file
Right click on the File, choose Run As, choose Run on Server. It will open in a default web browser, you will see the following content
That’s it for this post, if you like this post, please share this post with your friends and collogues and also share this on your social media profiles.