| Introduction to Java Server Pages |
| |
| Sample Example |
| |
| Print the following text into 'index.jsp' file and save it: |
<html>
<head>
<style>p { font-family:tahoma; font-size:14pt; }</style>
</head>
<body>
<%
String name = "Aman Kumar";
%>
<p>Hello <%= name %>!</p>
</body>
</html> |
| |
| Explanation |
| Above page appears to be a simple HTML page except one line of Java code between the <% and %> tags. These work the same way as <% %> tags in ASP. We can add server side Java code between these tags. In this case we simple declared a variable 'name' of type String ( simple text ) and initialized it with a value of "Aman Kumar", we can substitute our own name if we want. |
| |
<%
String name = "Aman Kumar";
%>
Next we output the value of 'name' variable to the user.
<p>Hello <%= name %>!</p>
|
| |
| Start Tomcat server and point your browser to http://localhost:8080/star/index.jsp to see JSP page running |
|
| |
| |
|
|
| |
| |