This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "JSP format" Watch "JSP format" New topic
Author

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>";
%>
<P>
<HR>
This page © 2000
<A HREF="http//www.my-company.com/">my-company.com</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
Greenhorn

Joined: Sep 22, 2000
Posts: 28
Cameron,
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
author
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!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: JSP format
 
Similar Threads
confused about the limitation of the jsp:include tag
Jsp not accessing bean class !
Access Counts in JSP
A tiny JSP page: How is this possible?
session tracking