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> ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
