AnsweredAssumed Answered

Processing form data from HTML POST

Question asked by jcobb on Aug 14, 2009
Latest reply on Aug 15, 2009 by jcobb
Hi
I've been getting on well with creating a first surf application - but have a query regarding the best architecture to adopt in processing user data posted to a url from a browser form.

I've already created a 'login' component that can appear on any page - it uses an html form to accept username / password, and posts to the '/login' url. A hidden field passes the current page as the success or failure urls - so the user ends up back at the same page whatever happens. The component checks for currently logged in user, and will display the username and a 'log out' link rather than the form if logged in.

So far the logout link is not ideal - it doesn't return the user to the same page as the Logout servlet doesn't allow us to pass a success url like login.

Now I want to create a 'register' component. I've successfully created an html form - but now need to write my own webscript to process the user input. My first attempt was to create a 'register' page and post the form data there. However none of my other component webscripts are set up for POSTs - only GETs, so they all throw errors. My register component should be completely independent of the page it's on, or other components, so it's not acceptable to create POST versions of all pages and components.

So now I've set up a webscript - processRegister. The idea is that rather than posting the form to a page url, we post to the webscript which will handle all the registration logic, then redirect back to whatever page the register component form was displayed on.

The login servlet uses response.sendRedirect - but I don't think this will be available.

I can't easily see how share processes posted data - it's all wrapped up in the gui.

So my questions are:

1. Is it a sensible architecture to create a webscript to handle posted form data for each component that uses an html form on the site, and then have it redirect back to the page we came from?
2. What api can I use from a webscript to redirect to a page (like the login servlet does)?

Outcomes