Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP format

 
Cameron Park
Ranch Hand
Posts: 371
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 371
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Peter!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic