different examples of jsp codes
TRANSCRIPT
![Page 1: Different examples of jsp codes](https://reader035.vdocuments.us/reader035/viewer/2022062513/5560dd35d8b42aa65e8b4763/html5/thumbnails/1.jpg)
Different examples of JSP codes.
Karen Martinez.1101.
![Page 2: Different examples of jsp codes](https://reader035.vdocuments.us/reader035/viewer/2022062513/5560dd35d8b42aa65e8b4763/html5/thumbnails/2.jpg)
● For creating our first JSP the meanings of programation are the minimum we must have.
● 1. The first thing we have to know is that each JSP page is going to generate us a HTML page. That's why we have to have a HTML page created that includes Java codes and it produces our JSP program.
![Page 3: Different examples of jsp codes](https://reader035.vdocuments.us/reader035/viewer/2022062513/5560dd35d8b42aa65e8b4763/html5/thumbnails/3.jpg)
2. It's important to keep in mind that our JSP document is a HTML page with its own structure where it is mixed together with the Java code.
3. When we want to introduce Java code we will make it with <% and %> symbols.
![Page 4: Different examples of jsp codes](https://reader035.vdocuments.us/reader035/viewer/2022062513/5560dd35d8b42aa65e8b4763/html5/thumbnails/4.jpg)
● In this part you will find an example of the codes that are necessary for a JSP program.
![Page 5: Different examples of jsp codes](https://reader035.vdocuments.us/reader035/viewer/2022062513/5560dd35d8b42aa65e8b4763/html5/thumbnails/5.jpg)
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>My first JSP</title>
</head>
<body>
<h1>My First JSP</h1>
<% // Java code %>
</body>
</html>
![Page 6: Different examples of jsp codes](https://reader035.vdocuments.us/reader035/viewer/2022062513/5560dd35d8b42aa65e8b4763/html5/thumbnails/6.jpg)
4. For introducing some Java content in the page we will use the following function:
<% out.println("Text to put on the page "); %>
![Page 7: Different examples of jsp codes](https://reader035.vdocuments.us/reader035/viewer/2022062513/5560dd35d8b42aa65e8b4763/html5/thumbnails/7.jpg)
5. Even if it has no more Java code, we can replace it with the next code:
<%= "Text to put on the page" %>
6. Finally we must know that for saving any file we use ''.jsp'' label.
![Page 8: Different examples of jsp codes](https://reader035.vdocuments.us/reader035/viewer/2022062513/5560dd35d8b42aa65e8b4763/html5/thumbnails/8.jpg)
Another example of JSP.
● The second example is going to be called: prog1.jsp:
%
int base=0,altura=0; double area=0;
if(request.getParameter("OK") != null)
{
![Page 9: Different examples of jsp codes](https://reader035.vdocuments.us/reader035/viewer/2022062513/5560dd35d8b42aa65e8b4763/html5/thumbnails/9.jpg)
Base: Integer.parseInt(request.getParameter("BASE"));
Height: Integer.parseInt(request.getParameter("HEIGHT"));
area: base * height / 2.0 ; };
![Page 10: Different examples of jsp codes](https://reader035.vdocuments.us/reader035/viewer/2022062513/5560dd35d8b42aa65e8b4763/html5/thumbnails/10.jpg)
out.println("<FORM ACTION=prog1.jsp METHOD=post>"
out.println(“Show the base:<INPUT TYPE=TEXT NAME=BASE value="+base+"><BR>");
out.println(“Show the height:<INPUT TYPE=TEXT NAME=ALTURA value="+height+"><BR>");
![Page 11: Different examples of jsp codes](https://reader035.vdocuments.us/reader035/viewer/2022062513/5560dd35d8b42aa65e8b4763/html5/thumbnails/11.jpg)
out.println("AREA:<INPUT TYPE=TEXT NAME=AREA value="+area+"><BR>");
out.println("<INPUT TYPE=SUBMIT NAME=OK VALUE=evento1 ><BR>"); out.println("</FORM>"); %>
![Page 12: Different examples of jsp codes](https://reader035.vdocuments.us/reader035/viewer/2022062513/5560dd35d8b42aa65e8b4763/html5/thumbnails/12.jpg)
And the third one.
First program of adding two numbers in JSP:
<%@ page language="java"%>
<html>
<head>
<title>Add number program in JSP</title> </head>
<body>
<% int a=5; int b=2;
int result=a+b;
![Page 13: Different examples of jsp codes](https://reader035.vdocuments.us/reader035/viewer/2022062513/5560dd35d8b42aa65e8b4763/html5/thumbnails/13.jpg)
out.print("Additon of a and b :"+result);
%>
</body>
</html>
![Page 14: Different examples of jsp codes](https://reader035.vdocuments.us/reader035/viewer/2022062513/5560dd35d8b42aa65e8b4763/html5/thumbnails/14.jpg)
THANKS.