Você está na página 1de 3

A Statice Page

<html>
<body>
<table width="200px" border="1px">
<tr>
<td>Islington College</td>
<hr>
</table>
</body>
</html>
Converting Above static page into dynamic through jsp
<html>
<body>
<table width="200px" border="1px">
<tr>
<td><% out.print("Islington College")%></td>
OR
<% = "Islington" %>
<hr>
</table>
</body>
</html>
<%----%> => expression tag
<%!----%> => declaration tag
eg.1
<%!
void display()
{
out.print(a);
}
%>
eg. 2
<%
out.print(a);
void display()
{
out.print(a);
}
%>
manageable code
<body>
<%! int a = 20; %>
<%
out.print(a);
%>
</body>
JSP comment

<%----%>
//
Using for loop in two ways
Simple form of for loop
<html>
<body>
<%
String[]name={"Ram","John","Sita","Selina"};
for (int i=0; i<name.length; i++) {
out.print(name[i]);
}
%>
</body>
</html>
Extended for loop: used to extract all data from database
<html>
<body>
<%
String[]name={"Ram","John","Sita","Selina"};
for(String value:name){
out.print(value);
}
%>
</body>
</html>
Embedding html code in jsp
<html>
<body>
<%
String[]name={"Ram","John","Sita","Selina"};
for(String value:name){
out.print(value+"<br/>");
}
%>
</body>
</html>
Printing all the name in a table
<html>
<body>
<%
out.print("<table width='200px' border='1px'>");
String[]name={"Ram","John","Sita","Selina"};
for(String value:name){
out.print("<tr>");
out.print("<td>"+value+"</td>");
out.print("</tr>");
}
out.print("</table>");
%>

</body>
</html>
<html>
<body>
</html>
Display Content on web Browser writing Servlet
public class ServletExample extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse res
ponse){
response.setContentType("text/html");
PrintWriter write = response.getWriter();
writer.println("Hellow");
System.out.print("Hello");
}
}

Você também pode gostar