> For the complete documentation index, see [llms.txt](https://gyansetu-jspandservlets-for-java.gitbook.io/workspace/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gyansetu-jspandservlets-for-java.gitbook.io/workspace/hello-jsp.md).

# Hello JSP

### Need:

Java code inside HTML.

![](/files/-LeSV6KdPtOhFP21tK1u)

![](/files/-LeSV8wuQbLj8kZt9a_d)

![](/files/-LeSVEHQ2EAbQZASXb3a)

Step : Run on server

![](/files/-LeSVM3NiKz2IgXfULjp)

![](/files/-LeSVGSX-gOEHHyFSs0w)

### Writing java code:

#### Way 1: using <% . ....  %>

```markup
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
	<h1>Hello</h1>
	<%
		int i = 3;
		int j = 8;
		int k = 3 + 8;
		out.println("Value of k is " + k);
	%>

</body>
</html>
```

#### Way 2:  using <%=%>

```markup
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
	<h1>Hello</h1>
	<%
		int i = 3;
		int j = 8;
		int k = i + j;
		out.println("Value of k is " + k);
	%>

	<%
		int l = 3;
		int m = 12;
		int n = l + m;
	%>
	Value of n is
	<%=n%>

</body>
</html>
```

![](/files/-LeSWdaCjBoW4NQI400z)

#### Way 3 : <%!...%>

```java
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
	<h1>Hello</h1>
	<%!public int sum(int a, int b) {
		return a + b;
	}%>

	Value of sum of 67 and 89 is
	<%=sum(67, 89)%>
	<br>
	<%
		int i = 3;
		int j = 8;
		int k = i + j;
		out.println("Value of k is " + k);
	%>
	<br>

	<%
		int l = 3;
		int m = 12;
		int n = l + m;
	%>
	Value of n is
	<%=n%>

</body>
</html>
```

![](/files/-LeSXbCWZm_WxUYb5LIT)
