File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes JSP format Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "JSP format" Watch "JSP format" New topic

JSP format

Cameron Park
Ranch Hand

Joined: Apr 06, 2001
Posts: 371
Hi, I am a bit confused. Does JSP have to be in HTML format? Can
<%@ page import="java.util.Date" %>
<%-- The following become fields in each servlet that
results from a JSP page that includes this file. --%>
private int accessCount = 0;
private Date accessDate = new Date();
private String accessHost = "<I>No previous access</I>";
This page © 2000
<A HREF="http//"></A>.
This page has been accessed <%= ++accessCount %>
times since server reboot. It was last accessed from
<%= accessHost %> at <%= accessDate %>.
<% accessHost = request.getRemoteHost(); %>
<% accessDate = new Date(); %>

be considered a valid JSP file?

Paul Ramsden

Joined: Sep 22, 2000
Posts: 28
It depends on what action you want the JSP to perform. Normally, you still need the usual <HTML><BODY></BODY></HTML> tags if you want to present information to the user in a browser but, theoretically, a JSP could perform an 'invisible' task.
The JSP compiler translates your JSP into a servlet which, at runtime, outputs all the plain HTML in your JSP as-is and executes the java code in the <% %> tags.
What arrives at the browser should be valid and plain HTML (or something the browser can recognise e.g. XML, plain text )

Peter den Haan
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Originally posted by Cameron Park:
Hi, I am a bit confused. Does JSP have to be in HTML format?

No. A JSP can be in any format, although in practice you are restricted to text-based formats. Don't forget to set a proper response MIME type for what you're generating.
Obviously, whatever format you generate has to be something the client expects (a browser would typically expect plain text or HTML, a WAP phone expects WML, an XSL engine would expect a specific XML vocabulary). But that is really outside the scope of the JSP proper. The JSP engine doesn't care what format you generate.
- Peter
Cameron Park
Ranch Hand

Joined: Apr 06, 2001
Posts: 371
Thank you Peter!
I agree. Here's the link:
subject: JSP format
jQuery in Action, 3rd edition