views:

25

answers:

1

I want to know how can I create new account using servlets in post method?

I'm currently following MVC design pattern, and I want to know if I pass the required data to register new account from JSP page, then how can I get that data in post method? As request.getParameter() method returning me null. How can I know that post method is calling to create new account?

How can I pass all the relevant user information from servlets to model class for registering data to the database table?

+1  A: 

If request.getParamter() returns null, then the problem needs to be solved somewhere else. Maybe wrong form encoding? Maybe wrong parameter name? It's basically not that hard. A HTML form like this in the JSP..

<form action="register" method="post">
    <input type="text" name="username">
    <input type="submit">
</form>

..in combination with a Servlet which is mapped in web.xml on an url-pattern of /register and the following in the doPost() method..

String username = request.getParameter("username");

..should just work. Then you just create a new model class, fill it with those values and pass it to the DAO class to persist it in the DB.

I suggest to get yourself through those excellent basic JSP/Servlet tutorials to get yourself started: http://courses.coreservlets.com/Course-Materials/csajsp2.html

You may also find this basic DAO tutorial useful, the 2nd part exist of a basic JSP/Servlet example handling a simple use case of "Register user", exactly what you need.

BalusC