In general, the idea is good. A few comments.

This is a typical logged-in/not-logged-in dual view.
It is common to make the not-logged-in view a login
screen with user ID/password. The same page is a
destination for logout with a logout message.
The message feature is also used for unseccessful 
login attempt.

It's good to think about the logged-in/not-logged-in
feature as a switch that represents two views, as
a markup control:

  <% if. loggedIn'' do.
       transfer 'loggedIn.jhp'
     else.
       transfer 'login.html'
     end. %>

Where the logic of loggedIn verb is hidden somewhere
in the implementation specifics: cookies, etc.

The method of substituting alternative screens,
as you have, is Transfer. The other way is Redirect,
which causes a trip to the client, but will provide
a different URL--whether it's good thing depends
on intention--whether you want to show the difference
between public and secure parts of the web site.

Another way is instead of 3 pages have two:
one login page, and the other main logged-in page with
  ...
  <% load 'script.ijs' %>
  <% if. -.loggedIn'' do. transfer 'login.html' end. %>
  ... rest of the page

It's good to have a few alternatives for passing
control between pages:
 - transfer: abandon current
 - execute: resume current
 - redirect: send new URL for client refresh

It would be good for them to understand relative paths
as well as '~CGI/' based paths and map to correct URL
or physical path.
For any non-JHP file they would just
  
  ContentType mimeForFile file  NB. runs once
  stdout fread file

>   'Firstname Lastname'=: getUserInfo ".uid

Another way is to do it in the target JHP page,
rather than sharing it between two code entities.

> coming straight from say Dreamweaver, they won't have '<%' as the first

HTML editors should support <% %>. However, maybe not as
first character--for this reason, should jhp recognize
markup as '<' rather than '<%'? Or even ('<%' +./@E. ]) ?

Unconditional hrun is 0!:[EMAIL PROTECTED]


--- "Sherlock, Ric" <[EMAIL PROTECTED]> wrote:

> In the application I want to create, I would like to separate the html
> page creation from "business logic" as much as possible.  Below is a
> sketched example of the sort of thing I'm thinking of doing. I'd be
> interested in any feedback as to whether this is a sensible approach or
> not.
> 
> Basically default.jhp checks to see whether the UserID cookie is set and
> therefore whether to load login.html or greeting.jhp. If the page is a
> JHP page, it is run through the JHP parser. Given the JHP pages will be
> coming straight from say Dreamweaver, they won't have '<%' as the first
> two characters, hence the need to append '<% %> to the front of the html
> to be parsed.
> 
> In a more complete version it might be more flexible to choose the page,
> read it from file, find out what info is required and then get that
> info, before running "hrun '<% %>',html"
> 
> ========================================================================
> ==
> default.jhp
> ========================================================================
> ==
> ContentType'text/html' [ Expires 1
>  
> uid=: qcookie <'UserID'  NB. Check for cookie
> fext=:'.'&(>:@i:~}.])
> isJHP=: 'jhp'-: fext
> getUserInfo=: 3 : '''Micheal'';''McDonald''' NB. placeholder for uid
> lookup verb
>  
> 3 : 0''
> if. ''-:uid do. NB. If cookie UserID is not set display login page
>   page=: '~CGI/login.html'
> else. NB. Else cookie UserID is set then get user info and display
> customised greeting page
>   'Firstname Lastname'=: getUserInfo ".uid
>   page=: '~CGI/greeting.jhp'
> end.
> html=: toJ fread jpath page 
> if. isJHP page do. html=: hrun '<% %>',html end.
> print html
> )
> 
> ========================================================================
> ==
> login.html
> ========================================================================
> ==
> <html>
>   <head>
>   <title>test html</title>
>   </head>
>   <body>
>    <h1>Gidday!</h1>
>    <p>I don't know who you are yet. You need to log in first</p>
>   </body>
> </html>
> 
> ========================================================================
> ==
> greeting.jhp
> ========================================================================
> ==
> <html>
>   <head>
>   <title>test jhp</title>
>   </head>
>   <body>
>    <h1>Gidday <%= Firstname %>!</h1>
>    <p>You are <%= Firstname %> <%= Lastname%></p>
>    <p>The time is <%= 6!:0 '' %> </p>
>    <p>Let's get started.</p>
>   </body>
> </html>



       
____________________________________________________________________________________
Need a vacation? Get great deals
to amazing places on Yahoo! Travel.
http://travel.yahoo.com/
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to