caucho
Resin
FAQ
Reference Guide
Demo
Tutorial

JSP page
Config
URLs
Database Forms
XTP Copy
Hello Tag
Vary Filter
HardCore
Mailing Forms
Beans
Cache
XSL Filter
run-at

Servlet
Parse Errors
Runtime Errors
Debugging
 Adding a JSP page

Tutorial
Tutorial
Servlet

The sample page you'll be creating adds 2 + 2 and displays the result in the browser.

JSP pages are created by putting a add.jsp file in the document directory. The JSP page is a mixture of HTML and Java code. Resin's JSP engine compiles the .jsp file into a Java servlet and then runs the servlet to produce the output.

Resin's web server stores its pages in a directory named doc. On this machine it's D:\java\resin-2.1.12\doc\

Create the text file doc/test/add.jsp (D:\java\resin-2.1.12\doc\test\add.jsp) with your favorite text editor: notepad, emacs, vi, or whatever. It should contain the following text:

add.jsp
2 + 2 = <%= 2 + 2 %>

To see Resin in action, you need to look at the page in the browser. The URL is http://gshightecher.com:80/test/add.jsp

If everything works, you should see the following page:

2 + 2 = 4

An explanation

The web server uses the '.jsp' extension to make 'add.jsp' an active page. For HTML pages and GIF files, the web server just copies the file from your computer to the browser. That's why looking at the file index.html in your browser looks the same as looking at http://localhost:8080/index.html.

By default, Resin copies text to the browser. For example, Resin copied the '2 + 2 = ' to the browser. In fact, if you wrote a JSP file with no special tags, Resin would copy it entirely to the browser; it would be equivalent to an '.html' file. Resin is smart enough to see that the page is static, so it can avoid working hard.

The special tags '<%' and '%>' tell Resin to do something active, something script related. You will only need to learn a few of these special tags:

TagMeaning
<%@ ... %>Directive
<%= ... %>Java expression
<% ... %>Java function
<%! ... %>Java declaration

In the add.jsp example, the expression tags, e.g. <%= 2 + 2 %>, tell Resin to evaluate the text as a Java expression and print the result to the browser. In this case, 4.


Tutorial
Tutorial
Servlet
Copyright © 1998-2002 Caucho Technology, Inc. All rights reserved.
Resin® is a registered trademark, and HardCoretm and Quercustm are trademarks of Caucho Technology, Inc.