different examples of jsp codes

14
Different examples of JSP codes. Karen Martinez. 1101.

Upload: karenm30

Post on 24-May-2015

139 views

Category:

Technology


5 download

TRANSCRIPT

Page 1: Different examples of jsp codes

Different examples of JSP codes.

Karen Martinez.1101.

Page 2: Different examples of jsp codes

● 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

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

● 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

<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

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

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

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

Base: Integer.parseInt(request.getParameter("BASE"));

Height: Integer.parseInt(request.getParameter("HEIGHT"));

area: base * height / 2.0 ; };

Page 10: Different examples of jsp codes

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

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

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

 out.print("Additon of a and b :"+result);

%>

</body>

</html>

Page 14: Different examples of jsp codes

THANKS.