Upload
karenm30
View
139
Download
5
Embed Size (px)
Citation preview
Different examples of JSP codes.
Karen Martinez.1101.
● 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.
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.
● In this part you will find an example of the codes that are necessary for a JSP program.
<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>
4. For introducing some Java content in the page we will use the following function:
<% out.println("Text to put on the page "); %>
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.
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)
{
Base: Integer.parseInt(request.getParameter("BASE"));
Height: Integer.parseInt(request.getParameter("HEIGHT"));
area: base * height / 2.0 ; };
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>");
out.println("AREA:<INPUT TYPE=TEXT NAME=AREA value="+area+"><BR>");
out.println("<INPUT TYPE=SUBMIT NAME=OK VALUE=evento1 ><BR>"); out.println("</FORM>"); %>
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;
out.print("Additon of a and b :"+result);
%>
</body>
</html>
THANKS.