I've created an html form that allows the user to login, or register.

Here is what I've thought about(just for the registration page, not login):

HTML FORM --> servlet ---> servlet calls java class that verifys the data, and shoves it into the database... ----> Makes a few tests --- > sends a dispatch to the jsp page that lets the user know it was succesful or not.

Is that good so far? I'm trying to seperate all the logic, but I'm not sure if the servlet should be there or not.

Data Layer -- > java class
Business logic layer(Sorft of) -- > servlet
present layer -- > jsp page

I'm basing it off of that, but I don't know if it makes sense what I'm doing?

Recommended Answers

All 6 Replies

I think it sounds good. Just try to get the input checking away from the servlet and into the java class you're talking about. Java classes (beans) should have that responsibility, and servlet should dispatch the request to the appropriate jsp page, according to if the registration was successful or not. You could of course avoid the java class by putting everything in the servlet, but if you're thinking about reusing the servlet (Controller in the classical MVC pattern), you would be best served with keeping that file as small as possible.

Almost right, but not quite how I'd prefer it.

Data is transmitted to a servlet. This servlet controls who is to process the data (based on request attributes probably).
It then forwards the data somewhere else for processing. This can be another servlet, a javabean, or even a JSP (in extreme cases like there's nothing to do but just show the data again).
This then tells the controller (if it's not displaying the data itself like a JSP would) which then decides what to do with the result (most likely this will be forwarding to a JSP or servlet for sending it back to the client).

You will likely be better off using a preexisting framework for all this. Something like Spring would serve well.

Should I use simpler technologies like javascript to do this?

Is there advantages of using cgi type scripts like servlets and jsp as opposed to simple validation with something like javascript?

Is there advantages of using cgi type scripts like servlets and jsp as opposed to simple validation with something like javascript?

There is at least one very obvious advantage: Jacascript can be turned off on the client side, meaning that validation won't happen at at all. Always write applications that doesn't require javascript to be useable.

And, I agree with jwenting: A framework would help. Try out Spring ( http://www.springframework.com ), for instance. It takes some time to get into it, but it's well worth the time. You'll get it back in saved development hours.

Javascript validation can be easily circumvented.

A classic (and true) story is an online store that used only Javascript validation.
A customer quickly found out what requests to send and was thus able to modify his order to a price of $1 for goods worth tens of thousands.

The company took him to court where the judge threw out the case on the grounds that a website is effectively a storeclerk and if a storeclerk charges you an amount that's what you have to pay.

I'm new to the javascript and html thing. I really don't think it's much fun I'm trying to find use for it. It's hard going from java to something like that :sad:

I believe I will try the Spring Framework. Probably be a while before I get around to it, as I've got a billion books to read.

Thanks guys.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.