Javascript  
 
  ScriptJava  
 
  Perl  
 
  PHP  
 
  ROR  
 
  ask us  
 

 

Applications
  1. Getting started
  2. Definitions
  3. First program
  4. Characters and Strings
  5. Object and methods
  6. Arrays and Circles
  7. Exceptions
  8. The main method
  9. Reading
  10. Writing file
  11. Vectors
  12. Stacks
  13. Map The Dictionary
  14. Lists
  15. Linked lists
  16. Collection
  17. Interfaces
  18. Scanner
  19. StringTokenizer
  20. Generics
  21. JDBC
  22. DataBase Queries
  23. JSP, The main step

Graphics

Applets
  1. Regards
  2. One Picture
  3. Calculator
  4. Random pictures
  5. Bouncing picture

Swings
  1. Buttons listeners
  2. TextFields
  3. Swing Example

JavaBeans
  1. The first step
  2. Example

Search a word:
   



© The scientific sentence. 2010

JSP, The first step
JSP, The first step



I. Indroduction

JSP stands for JavaServer Pages. Like JavaScript, 
or PHP languages, where their scripts reside within HTML tags; 
JSP uses exactly the same manner. 
The JSP program saved as file.jsp contains Java code 
between the scriptlet <%  %>; wrapped in HTML tags using 
some features, mainly:  declarations, expressions, 
and directives like:

 <%! declarations %>  as 
private int Fibonacci(int n){
if(n <= 1){return n;}
else{return (Fibonacci(n - 1) + Fibonacci(n - 2));}}

 <%= expression %>  as 
<%= (new java.util.Date() ).toLocaleString() %>

 <%@ directive attribute1="value1" %>  as  
<%@ page import="java.util.*" %>
<%@ page import = "package1.*, package2,*,..." %>

JSP and Servlets have the same purpose; To run Java 
programs wrapped in HTML tags in the server side.


Once Tomcat is installed and configured, set the file.jsp as the following: 

1. The location of the file.jsp is:
C:\Program Files\Apache Software Foundation\Tomcat 6.0\
webapps\examples\
where  a subdirectory is created such as NewWork\. Finally, 
files.jsp are nested in:
C:\Program Files\Apache Software Foundation\Tomcat 6.0\
webapps\examples\NewWork\

2. To execute this program file.jsp, call it at:
http://localhost/examples/NewWork/file.jsp
(The related port for Tomcat,here, is set at localhost) 


2. Examples:

Example1 

<html>
<head>
<title>JSP Test Page: Regards</title>
</head>
<body>

<h1>Regards</h1>

<%
out.println("\t<P> To say: Regards </P>");
for(int c = 1; c < 3; c++)
{
out.println("\t<P> " + c +". Regards </P>");
if (c==2){ out.println("\t<P> " + c +". All the best 
of luck. </P>");}
}
%>
<BR>
<%
out.println("\t<P> To make the factorial of the three first 
numbers </P>");

int k = 1;

for(int j = 0; j <= 7; j++)
{
if (j <=1){ 
out.println("\t<P> the factorial of " + j + " 
is 0. </P>");
}
else { 
k = k*j;
out.println("\t<P> The factorial of " + j + " is 
" + k + " </P>");
}

}

%>

</body>
</html>

Example 2:

<html>
<head>
<title>Some Math</title>
<%!
private static double PI = 3.1415;
private int Fibonacci(int n)
{
if(n <= 1){
return n;
}
else{
return (Fibonacci(n - 1) + Fibonacci(n - 2));
}
}
%>

</head>

<body>
<h2>JSP Fibonacci program</h2>
<p>The Fobonacci of 7 is : <%= Fibonacci(7) %></p>
<p> PI * Fobonacci of 7 is : <%= PI * Fibonacci(7) %></p>

<p><font size = "<%=4%>">Right now, the time is :
</font></p>  
<%@ page import="java.util.*" %>
<%= (new java.util.Date() ).toLocaleString() %>


</body>
</html>


  
Google
Web
ScientificSentence
 




chimie labs
|
scientific sentence
|
java
|
php
|
green cat
|
contact
|


© Scientificsentence 2009. All rights reserved.