| ★ wanayoo — archive 1999 http://wdvl.internet.com/Authoring/Java/Servlets/java_server.html | Nouvelle recherche | Portail wanayoo |
|
|||
Java Server PagesApril 5, 2000
As described earlier JSP build on the ASP technology and use Java as a programming language. We saw the WelcomeServlet which takes myName as a parameter from HTML-form and displays a personalized welcome message. Now let's see how to achieve the same with a JSP: Welcome.jsp:
<HTML>
<HEAD>
<B> Welcome <%= request.getParameter("myName")%>
</B>
</HEAD>
</HTML>
That's all ! Suddenly life's become easy huh? The code between "<%" and "%>" is executed at the server and the HTML, with the results, is passed back to the client. One important fact about JSP one should always keep in mind is: every JSP is internally converted into a servlet. So even if it looks simple it it is probably going to put more 'load' on your m/c. A rule of thumb is 'if you have a lot of HTML code and some 'run time variables' use JSP. If you need a lot of processing, a servlet is the best choice. Actually one can 'interleave' servlets and JSP. We will see that in the next section. There are some pre-defined objects (such as request, response and session) available to each JSP. We can use all the normal programming constructs such as:
<% if ((request.getParameter("myName") == "Harshal") {%>
<B> Hey we have the same name !</B>
<% } else { %>
<B> Welcome <%= request.getParameter("myName") %> </B>
<%} %>
Finally, we can call methods of an external program - Java bean. Additional JSP resources:
Building Web Applications Using Servlets and JSP The Session Object | |||
internet.com
| |
e-commerce
|
Copyright 1999-2000 internet.com Corp. Legal Notices. Privacy Policy.