Start Simple java code for validating user in servlets

Simple java code for validating user in servlets

The better approach is extending Generic Servlet (like Window Adapter to close the frame) which contains only one abstract method service().

Even the service() method is non-abstract and infact with Http Servlet, the service() method can be replaced by the methods do Get() or do Post(). The above code works fine even if Generic Servlet is extended instead of Http Servlet. public void service(Http Servlet Request req, Http Servlet Response res) throws Servlet Exception, IOException service() method is a callback method called automatically when the container loads the servlet for execution when the client request comes.

The method takes two parameters – an object of interface Http Servlet Request and an object of interface Http Servlet Response and let us see what these interfaces meant to servlet.

I don't want users to be able to see the or until they are signed in.

It is fine if they view sign In and sign before signing in.

a) Http Servlet Request interface Following is the hierarchy.

The first parameter can be either of Servlet Request or its sub-interface Http Servlet Request.

The validation process works fine standalone,but I want to redirect the user to a home page on successful login and error page on failure.

My form is below: Here I print the JSON result on success and failure. But,when I run the application it just prints the json result instead of returning it back to the success/failure function in the js file.

Having said that, your Servlet is not setting a content type prior to outputting your "JSON" string, so it's defaulting to text/html. I'd have to see your complete login page, grid page and source for both Servlets. Each Servet should be mapped separately, as shown below. Could you please send me an example with CRUD operations using it or point to some useful links for the same??

That, and the full page submit you're doing, is why you only see your "JSON result" and not your grid page. If possible, attach a file containing these items and I'll be glad to take a look. Also, lowercase class file names violate Java naming conventions and the use of the 'default' package is discouraged. An easy one to start off understanding spring and its integration with extjs.

The responsibility of the data to be sent (like valid or invalid etc.) to the client is taken care by Http Servlet Response. Content Type("text/html"); set Content Type(String) is a method of Servlet Response inherited by Http Servlet Response and its job is sending the information to client’s browser of how the response sent by the servlet is to be formatted. That is, the data sent to the client is either in text format (as in ("VALID")) or HTML format (as in (INVALID)). This is more called as setting the MIME (Multipurpose Internet Mail Extension) type. get Parameter(String) method of Servlet Request (inherited by Http Servlet Request) takes a string parameter and returns a string.