MVC architecture with servlets and jsp

The following two tabs change content below.
Prasad Kharkar is a java enthusiast and always keen to explore and learn java technologies. He is SCJP,OCPWCD, OCEJPAD and aspires to be java architect.

Latest posts by Prasad Kharkar (see all)

In this tutorial we are going to learn how to create a simple MVC application using servlets and jsp.

MVC i.e. Model-View-Controller is a pattern helpful separation of concerns.

  • Model represents a POJO object that carries data.
  • View is the layer in which the data is presented in visual format.
  • Controller is the component which is responsible for communication between model and view.

A user always sees the view and communicates with the controller. We will understand this using a sample login application which will display a welcome username message and if the login fails, it will redirect to an error page. Here is what we are going to create.

  • login.jsp :- this will input username and password
  • success.jsp :- If login is successful, then this page is displayed
  • error.jsp :- If login is not successful then this page is displayed.
  • LoginController.java :- This is controller part of the application which communicates with model
  • Authenticator.java :- Has business logic for authentication
  • User.java :- Stores username and password for the user.

Requirements:

  • Eclipse IDE
  • Apache tomcat server
  • JSTL jar
      Create a new Dynamic web project in eclipse by clicking File -> New -> Dynamic Web Project. Fill the details i.e. project name, the server. Enter your project name as “MVCDemo”. You will get the following directory structure for the project.
Initial Project Structure
Initial Project Structure

 

      Create success.jsp, error.jsp and login.jsp and LoginController servlet, Authenticator class, User class in the packages as shown in the images. Put the jstl.jar in WEB-INF/lib folder.

 

File Structure
File Structure
Package Structure
Package Structure

 

 

 

Now that we have file structure, put this code in corresponding files.

 

Authenticator.java

User.java

error.jsp

login.jsp

success.jsp

and the web.xml

We are done with the code. Let us try and run it.

Start your tomcat server and hit url http://localhost:8080/MVCDemo/login.jsp.

You should be able to view this page.

loginForm

Enter username as “prasad” and password as “password”. You will see the message “Welcome prasad”.

Let us understand what happens under the hood with the help of diagram.

MVCFlow

  1. First, user visits login.jsp page and fills out data and submits form.
  2. This causesΒ  LoginControllerΒ  to be invoked because of form action="LoginController" .
  3. In LoginController , following code causes the model to be invoked and set the User properties.

    and User user = new User(username, password); .
  4. rd.forward(request, response); causes the servlet to forward to jsp page.

success.jsp page displays the username with expression language Welcome ${requestScope['user'].username}.

Notable advantages of mvc pattern are:

  • This separate presentation layer from business layer.
  • The controller performs action of invoking the model and sending data to view.
  • Model is not even aware that it is used by some web application or desktop application. Authenticator class can be used by desktop applications also. Thus separation helps in re-usability.

Hope this helps in understanding how to create MVC application using servlets and jsp.

Share Button

Prasad Kharkar

Prasad Kharkar is a java enthusiast and always keen to explore and learn java technologies. He is SCJP,OCPWCD, OCEJPAD and aspires to be java architect.

180 thoughts on “MVC architecture with servlets and jsp

    • November 21, 2013 at 10:34 am
      Permalink

      Thank you Sudhir.

      Reply
      • May 14, 2015 at 10:14 pm
        Permalink

        Hi , Thank you very much for the information.In the above Example in the Authenticat class we have password and username .How to authenticate if they are stored in database in the above example.Thank you very much.

        Reply
        • May 15, 2015 at 9:59 am
          Permalink

          At beginner level, you can either create database connection from web application and read username and password from servlet and then check for equality. Or you can go for a better way of using Java Authentication and Authorization Service which can be used with tomcat, jboss or wildfly. Please follow these links

          jaas with mysql and jboss
          jaas with mysql and tomcat

          Reply
      • February 17, 2017 at 11:57 am
        Permalink

        Hi Prasad

        thank you for your tutorial. But, can you help me with an example of JSP and Database connectivity.

        Reply
      • August 28, 2017 at 12:08 pm
        Permalink

        very useful and systematic presentation for beginners and pros…..
        you are a good presenter
        thank you very much

        Reply
    • February 23, 2016 at 11:18 am
      Permalink

      very nice Explanation Prasad

      Reply
    • September 14, 2016 at 7:40 pm
      Permalink

      I understand easily
      Thank you sir

      Reply
  • November 21, 2013 at 3:18 am
    Permalink

    can you explain more about Struts,Hibernate,Spring with MVC and Front Controler Design Pattern .

    Reply
    • November 21, 2013 at 10:50 am
      Permalink

      Yes Sudhir, tutorials about them will definitely come soon. I am working on them. Thank you for reading and showing interest.

      Reply
      • May 26, 2016 at 4:27 pm
        Permalink

        sir i was make project online testing system on MVC but Occurred one error.
        all function well in my project but next question not going sir i am suffering it.

        Reply
        • May 26, 2016 at 5:40 pm
          Permalink

          Please check your exception logs, you’ll see something, you can post it here. I will try to help.

          Reply
  • November 22, 2013 at 10:25 pm
    Permalink

    can tell about, how to practice best because giving answer in interview like real world is difficult and developing any application from scratch is difficult for me at home. actually i want to use all java/j2ee,struts,hibernate,spring,DB (some part of XML & WebService also) as Home work. so can you give any idea or, can you give Question for developing small application which gives real world meaning to become exp.

    Reply
  • November 22, 2013 at 11:59 pm
    Permalink

    can you tell about, how to practice best because giving answer in interview like real world is difficult .

    Reply
    • November 23, 2013 at 1:03 am
      Permalink

      I would recommend you to take up a sample project and implement it using MVC architecture so that you will get to know the difficulties faced during development. For example, create a simple user registration form in which fields are entered on a JSP, access them in a servlet and again display the list of all registered users on a separate JSP page. Use MVC architecture in it.

      Reply
  • March 24, 2014 at 1:52 pm
    Permalink

    good one… thank u so much….

    Reply
  • April 23, 2014 at 12:30 pm
    Permalink

    very helpful.. finding for this for a long.. expecting more topics from u..

    Reply
    • April 23, 2014 at 1:11 pm
      Permalink

      Thank you Sandyp for good feedback πŸ™‚ I will fulfil your expectations πŸ™‚

      Reply
  • June 5, 2014 at 5:59 pm
    Permalink

    hello sir,
    i have started learning jsp and servlet…and at the same time doing project in both the technologies…
    So will you kindly tell me what would be the best start for me and what are the main topics in both which will help me in making project..

    Reply
    • June 5, 2014 at 11:59 pm
      Permalink

      Hi Nishad, now that you have learned MVC architecture well, learn about servlets, listeners and other web components. I would recommend you to use JSF if it is possible as it is event based framework.

      Reply
      • June 7, 2014 at 11:58 am
        Permalink

        thanks sir but i have no idea about jsf as of now…so will u tell me how ….?

        Reply
        • June 7, 2014 at 9:41 pm
          Permalink

          Right now if you don’t have idea about jsf, its good to start with servlets and JSP itself. JSF part can be done later once you’ve understood servlets and jsp πŸ™‚

          Reply
          • June 10, 2014 at 9:22 am
            Permalink

            ok…thanks sir….

          • June 11, 2014 at 6:24 pm
            Permalink

            Hi,
            sir i am getting a bit confused regarding “jsp” like it eventually change into servlet then what is the need of taking jsp…..if i want to make a design form for user entry like name,sex address in jsp and more on that using jsp only so can i make it or not…..
            plzz explain……

          • June 11, 2014 at 6:28 pm
            Permalink

            and if i want to run an applet code in “eclipse” then is it possible to run or not….
            if i make a ui form using applet then it would be a good idea………..????

  • June 5, 2014 at 9:41 pm
    Permalink

    Excellent Mr.Prasad, i have looking for this kind of explanation so far. can you please post some more examples

    Reply
    • June 5, 2014 at 11:54 pm
      Permalink

      Sravani, thank you for positive feedback :). I am constantly adding some nice articles. You can like theJavaGeek page on facebook for regular updates. I would also like to receive a feedback from you for any improvements and suggestions.

      Reply
  • June 6, 2014 at 1:45 am
    Permalink

    ThanQ sir…really itz useful to me as am doing a project now in my training period…am searching these kind of neat explaination thanq once again…and i want you to give more tutorials on how to connect db for update profile and i have 2 questions 1) am using NetBeans IDE…so any difference between eclipse am i hv to do any modification from ur tutorial?

    2) how to get photo as a input for update profile page… ThanQ in advance…

    Reply
    • June 6, 2014 at 10:36 am
      Permalink

      1. Though you are using netbeans, it may have a different directory structure, so instead of webcontent directory, it can have other one. The rules for a web application do not change. You just need to create a dynamic web project in netbeans and follow the process given in this tutorial
      2. You will have to use file upload functionality for uploading photo and while displaying, I recommend you simply store the uploaded photo on hard drive and put the location of photo in database. While displaying photo for profile, you can pick photo location from database and display on web page.

      I will certainly write more tutorials as per your suggestion πŸ™‚ Thank you for reading a positive feedback. Happy learning.

      Reply
  • June 11, 2014 at 6:35 pm
    Permalink

    sir,it would be a great favour if you help me in my project…..if you allow me then i will keep posting the queries and you guide me how to do it…….my project title is “Student Mangement SYstem”…its a live project…..want to use jsp and servlet….plz kindly guide me step by step…..

    thanks and regards,
    Nishad

    Reply
      • June 12, 2014 at 12:32 am
        Permalink

        ok thanks sir….

        Reply
      • September 21, 2016 at 3:03 pm
        Permalink

        Hii Prasad am I trying to intergrate jsp form and servlets via webservices for passing values from Jsp to servlets
        Suggest me some with example

        Reply
  • June 25, 2014 at 8:45 am
    Permalink

    Comparison of MVC implementation between J2EE and ASP.NET, Who is the best?
    what is the difference between the two….?

    Reply
  • July 24, 2014 at 3:35 pm
    Permalink

    How can I connect a already completed JSP with a Oracle database into a MVC?

    Reply
    • July 25, 2014 at 9:25 am
      Permalink

      You can create a class which returns the database connection and use that object into business logic i.e. model.

      Reply
  • July 26, 2014 at 10:50 pm
    Permalink

    Great tutorial, just one error. On the jsp file the line

    Welcome ${requestScope[‘user’].username}

    should be

    Welcome ${requestScope[‘user’].getUsername()}

    because your attribute is private and you have a getter for it

    Reply
  • July 31, 2014 at 11:32 pm
    Permalink

    Prasad bro…awesome explanatn .Tq so much and can u please update some more example on each topic of servlets and jsp so that would be better for beginners….

    Reply
    • August 1, 2014 at 10:35 am
      Permalink

      Hi Madhu, thank you for good feedback. You can find good tutorials for servlets and jsp right in the menu. Here

      Reply
      • August 7, 2014 at 11:36 pm
        Permalink

        Thank you bro…and core java concepts what you have given is that enough or we need to learn more ? Because i want put one year virtual experience on Java so is the concepts you explained core java and j2ee is sufficient ?

        Reply
        • August 8, 2014 at 7:45 am
          Permalink

          Knowledge is never enough πŸ™‚ but my articles will definitely be helpful.

          Reply
  • August 14, 2014 at 7:48 pm
    Permalink

    The explanation was excellent. I am now able to understand MVC architecture very well. Could you please post some examples on CRUD operations involving MVC architecture. That is one area that I want to improve.

    Reply
  • August 22, 2014 at 5:34 pm
    Permalink

    Nicely put. Can you please explain a bit more detail on how the login.jsp gets loaded first?

    Reply
  • September 6, 2014 at 2:40 pm
    Permalink

    please explain the use of jstl.jar

    Reply
  • September 24, 2014 at 11:54 pm
    Permalink

    Sir,

    I am a fresher btech IT . I have started learning J2EE for the past few weeks . I am facing some problem in structuring a MCV pattern in java . It would be very helpful if you can please guide me in this and if can send me a small example of the basic functionalities of INSERT, UPDATE , and DELETE features using Mysql in a MVC format . I would me eagerly waiting for you reply and would be very thankful if you can make some time form your busy schedule and help me

    Reply
    • September 25, 2014 at 8:32 am
      Permalink

      Hi Snigdhodeb, Please let me know the problems you are facing while creating application using mvc pattern. I will defintiely help you with it.

      Reply
  • October 16, 2014 at 8:55 pm
    Permalink

    Nice work prasad,Simpe but perfect

    Reply
  • Pingback:Coffee Advisor web application | Nigoutsi's Local Site

  • Pingback:Coffee Advisor web application | AM0335

  • October 27, 2014 at 9:38 pm
    Permalink

    Thank u….the article is very useful.After reading so many articles on other website I found this one neat,clear and to the point.I am from non cs background and now working in IT company and undergoing training in java.I think this will help me to clear my doubts and make me love coding

    Reply
  • October 28, 2014 at 11:59 am
    Permalink

    Thank You Very much…… I got a clear idea on MVC model……….
    It was very useful and easy to understand….. Keep Going…………..

    Reply
  • November 5, 2014 at 1:30 pm
    Permalink

    Hi Prasad do you have any other example in which a form has many input values and POJO model in such case.

    Reply
    • November 5, 2014 at 11:05 pm
      Permalink

      This form already contains two values in it. Could you please tell me what exactly you want to ask when you say it has many input values and POJO model in such case?

      Reply
  • November 10, 2014 at 11:56 am
    Permalink

    great article sir thank you so much

    Reply
  • November 28, 2014 at 12:22 pm
    Permalink

    Thank u prasad ,i got clear idea on mvc..please post more tutorials

    Reply
    • November 29, 2014 at 11:47 pm
      Permalink

      I am glad it was useful for you. I will surely keep writing πŸ™‚ Happy learning

      Reply
  • November 29, 2014 at 12:01 pm
    Permalink

    very simple and easy to understand..
    Its a good example….Thank you Prasad ….

    Prasad i have a quary corresponding to requestDispatcher…
    can u explain me in detail

    Reply
  • January 5, 2015 at 8:30 pm
    Permalink

    hi prasad,
    its a good example but if want to connect to a database how should it be done? can u help me with a example where the queries should be written?

    Reply
    • January 9, 2015 at 5:13 pm
      Permalink

      Hi Ruthvik, I didn’t exactly get what you wanted to say. Could you please elaborate?

      Reply
  • January 10, 2015 at 11:19 am
    Permalink

    Hi…,
    The tutorial is very good. I tried the same but m getting error in my LoginController.java.

    The error is here . It is sayinf “Cannot instantiate the type authenticator” at the first line and “The method authenticate(Stirng,String) is undefined for the type Authenticator”.

    Authenticator authenticator = new Authenticator();
    String result = authenticator.authenticate(username,password);

    please check and give me the reply asap.

    My IDE:Eclipse luna
    JDK7
    Tomcat 8

    Reply
    • January 10, 2015 at 5:12 pm
      Permalink

      It seems your container is not able to recognize Authenticator class. Could you please post full stacktrace?

      Reply
    • June 2, 2015 at 10:18 pm
      Permalink

      Hi,

      I think you have imported wrong class file.
      Please import mvcdemo.model.Authenticator;

      Reply
  • January 22, 2015 at 9:18 pm
    Permalink

    very good tutorial..superb prasad keep it up..:

    Reply
  • February 9, 2015 at 2:27 am
    Permalink

    Hi Prasad,great document you have written here,keep up the good work.I have tried all the mentioned steps,but when i hit the URL “http://localhost:8080/MVCDemo/login.jsp” i am getting a requested resource is not available, page not found error.Can you please help me out here.Many thanks.

    Reply
  • February 11, 2015 at 9:40 am
    Permalink

    Hello sir currently i working on the live project and ur tutorial is very useful to me

    but can u please help me in spring mvc give me some exaples and websites to learn online

    thank you

    Reply
  • February 11, 2015 at 10:45 am
    Permalink

    thanks sir for the information ,its very much helpful to me
    i am fresher i dnt have any experience in java, but i want to start up projects frm home using java technology, so plz can u suggest me the things wat and all i have to learn to develop project in java

    Reply
    • February 12, 2015 at 5:32 pm
      Permalink

      Hi Kavitha, I am glad it was useful for you. First decide what kind of project you want to do, then will be able to tell.

      Reply
  • March 3, 2015 at 12:10 am
    Permalink

    hello, pls tell what is the advantages to make jsp program by mvc struture rather then simple..

    Reply
  • Pingback:MVC architecture with servlets and jsp - theJav...

  • March 9, 2015 at 4:23 am
    Permalink

    Hello Prasad, thank you for this tutorial! Can you please discuss how packaging works in servlets? I always seem to get errors when I create packages for my servlets, and then try to import other classes and use their functions.
    Thank you!

    Reply
    • March 9, 2015 at 4:18 pm
      Permalink

      Hi Chris, there is no difference in servlet packages and normal package. Could you please post the errors you are getting? I’ll try to resolve them

      Reply
  • March 14, 2015 at 3:10 pm
    Permalink

    very good article..regards

    Reply
  • March 17, 2015 at 4:51 pm
    Permalink

    ….terrific MVC example thank u Sir πŸ™‚

    Reply
  • March 20, 2015 at 9:48 pm
    Permalink

    owsm……………………….

    Reply
  • March 25, 2015 at 10:54 am
    Permalink

    Hi………,
    Can you tell me if we want to print table in our jsp page and table value come from database and we use mvc architecture then it is correct to get all values in jsp page by directly write query in that jsp page or use servlet to get all values?

    Reply
    • March 25, 2015 at 11:51 am
      Permalink

      Hi Ashish, jsps are meant for displaying purpose only. a JSP developer need not have knowledge of sql queries. Writing sql or java code in jsp would break the mvc pattern. It is not advisable to write logic in jsp. You should use servlet or further layers to call values from database.

      Reply
      • March 25, 2015 at 2:49 pm
        Permalink

        Thanks Prasad ,
        it can clear all my concept about mvc pattern

        Reply
  • March 28, 2015 at 11:46 am
    Permalink

    sir, i created that architectur but how to run it..
    plz specify here….

    Reply
    • March 28, 2015 at 8:44 pm
      Permalink

      Hi Kapil, I’ve already explained how to run it. What is the problem you are facing? Please let me know.

      Reply
  • April 1, 2015 at 1:35 pm
    Permalink

    superb tutorial…. show me to database authentication of servlet mvc

    Reply
  • April 4, 2015 at 12:07 pm
    Permalink

    sir can u explain me if i dont use eclipse… how can i proceed in notepad

    Reply
    • April 4, 2015 at 3:47 pm
      Permalink

      you will have to compile all java files, servlet,jsp separately with respective commands (Need some googling for it). After that you need to create war file and then deploy under tomcat

      Reply
  • April 9, 2015 at 1:30 am
    Permalink

    Hi,

    I am trying to run the login Jsp , but I am facing 404 error also I am getting error for taglib in success.jsp.

    Please help.

    Reply
    • April 9, 2015 at 9:42 am
      Permalink

      please provide the stacktrace. Have you followed all the steps mentioned in the article?

      Reply
  • April 14, 2015 at 4:57 pm
    Permalink

    Thanks for this tutorial. I have a problem, if we have two classes for example, User and Admin , Admin extends User, how can we respect MVC architecture ? I mean in that case we will have two beans, two classes for DAO access ? thanks for helping

    Reply
  • April 18, 2015 at 8:01 pm
    Permalink

    Hello Prasad,
    I am confusing in MVC pattern that
    1. In project or MVC pattern how many servlet we can use in one project is it recommend that only one servlet is in all project or multiple we can use?what would be prefer.
    2.what difference between data transfer object class and data access object (DAO) class used in application.
    3.how we should hide DAO class from direct access in MVC pattern.

    Provide standard industrial coding procedure to me.

    Reply
  • April 25, 2015 at 10:29 pm
    Permalink

    Would it be possible to download the project ? It would help πŸ™‚

    Reply
  • May 23, 2015 at 8:01 am
    Permalink

    Thanks for the tutorial prasad, but i have a problem which is when i compile 3 of that java file, i got this error from LoginController.java, “package sun.text.normalizer.ICUBinary does not exist”… I dont know much about that package declaration… Can u help me…

    Reply
  • May 26, 2015 at 5:37 pm
    Permalink

    thanks for your example… it is very nice.. i have one question regarding above

    example whether we can use form in the layer between jsp and servlet controller?

    UserForm userForm

    String username = userForm.getUsername();

    like this one..

    Reply
  • June 9, 2015 at 12:51 pm
    Permalink

    Simply awesome example. Hats off to you Prasad ji… πŸ™‚

    Reply
  • June 9, 2015 at 8:16 pm
    Permalink

    Thank you Mr. Prasad. Your explanation on MVC was simple yet very detailed and helpful.

    I am currently develop an application for the organization I work for , I am using JAVA and I have a couple quesitons that I hope you can answer.

    Within the aformentioned application I want to implement Server Side validation, where would you put the said block of code, in the Model or the Controller class?

    Using your above example, lets assume that you wanted to ensure that the user entered both a password and username, would you put the validaiton block in the LoginController class or the Authenticator class?

    Secondly, what is the best way to implement User Privilleges and Permissions in JAVA using the MVC Design pattern? Do I implement an Intercepting filter and place the logic there or do I distrubute the logic between the view and model?

    Any advice would be greatly appreciated. Thank you much in advance.

    Kind Regards,
    Hakeem

    Reply
    • June 9, 2015 at 8:21 pm
      Permalink

      Hi Hakeem, I am glad you found it useful. To be honest there is no IDEAL way of doing things. This tutorial only explains how mvc architecture can be done using servlets and JSP. For authentication and authorization, I believe you should use Java Authentication and Authorization Service. You can find some tutorials on my blog itself. I am sure they will help.

      Reply
      • June 10, 2015 at 2:42 am
        Permalink

        Wow, Prasad. Thank you so much for your quick response. I am going to look at your tutorials now. Also, do you know of any tutorials site I can read up on Java Authentication and Autorizaiton ?

        Reply
  • June 25, 2015 at 4:42 pm
    Permalink

    How we can handle multiple request using single Controller(Servlet) like we do using filter in struts ? please explain with an example if possible.

    Reply
    • June 26, 2015 at 9:12 am
      Permalink

      There are some shortcomings with a simple MVC architecture in servlets and jsp and that is why struts provides that functionality πŸ™‚

      Reply
  • July 6, 2015 at 5:31 pm
    Permalink

    How to start learning JSP, Servlet?
    I got training in J2EE tech, but it went over my head. Cz, I am a slow learner!
    Now, I am trying to learn it myself. Please suggest me.
    And also, I got severely confused becoz, they taught MVC, DAO without explaining well.
    Tell me about that also.

    Reply
  • July 7, 2015 at 10:53 pm
    Permalink

    Hello! Sir.Myself Anish.I want to know how to retrieve all record from a table on a view page such as jsp.After retrieved we make the all the first rows provide a link…like as when we access the irctc rail site there we check the train and after checking if valid train all info then it render the all train details.when we click on the train no by link then it moved us book page thats so on…..please tell me how to implement in my project this proceedure…..ok

    Reply
  • July 13, 2015 at 1:07 pm
    Permalink

    Hi Prasad,
    This was very helpful. Thanks a bunch!

    Reply
  • July 13, 2015 at 3:52 pm
    Permalink

    Hello Prasad,

    Can you tell me which is the business logic in this example?

    Reply
    • July 14, 2015 at 8:48 am
      Permalink

      Hi Kannan, this is just a sample mvc architecture which elaborates different layers. Business logic term refers to the code which fulfills functionality. Although you can consider the model layer as business layer here.

      Reply
      • October 28, 2015 at 2:45 pm
        Permalink

        sir i need a solution for creating web app in framework-spring,hibernate,jsf

        Reply
        • October 29, 2015 at 10:50 am
          Permalink

          Hi Logesh,

          Please tell me the problem you are facing while building the app, I will try my best to help

          Reply
  • July 15, 2015 at 4:31 pm
    Permalink

    very good architecture..

    Reply
  • August 6, 2015 at 12:23 pm
    Permalink

    Thanks for good explanation

    Reply
  • August 7, 2015 at 11:34 am
    Permalink

    Hello sir ,
    i am fresher , i dont know actual working of mvc
    can u tell me how to implement servlet , jsp and how to get the connection

    Reply
  • August 10, 2015 at 12:47 pm
    Permalink

    sir..May i write multiple method in one servlet..
    if yes then how can we call from html that which particular one is getting to call

    Reply
  • August 11, 2015 at 9:22 am
    Permalink

    would you explain the way that I do not need to use the build path to have servlet.jar for my program.

    Reply
  • October 11, 2015 at 7:19 pm
    Permalink

    Thanks for your sharing! I am learning web service to build a Big data ecosystem between my Hadoop system and application. Your MVC JSP tutorial helps me!

    Reply
  • November 2, 2015 at 1:54 pm
    Permalink

    Simply out and awesomely explained πŸ™‚

    Reply
  • November 14, 2015 at 4:19 am
    Permalink

    Hi Prasad,
    i have more interest in programming ..
    i am a student of BSCS 1st semester reg from university of sargodha pakistan….
    can you help me…………..!

    Reply
  • December 2, 2015 at 5:49 pm
    Permalink

    isn’t mvc rule been broken here as you are using business logic (user authentication part) inside the controller.

    Reply
    • December 4, 2015 at 10:06 am
      Permalink

      Hi Asif, thank you for your comment. If you watch closely, there is a separate class called Authenticator which does the job of authentication. It is simply being called from the controller i.e. Servlet.

      Reply
  • December 12, 2015 at 2:19 am
    Permalink

    Excelent example!!!!

    Reply
  • December 14, 2015 at 12:26 pm
    Permalink

    Description Resource Path Location Type
    Access restriction: The type ICUBinary.Authenticate is not accessible due to restriction on required library C:\Program Files (x86)\Java\jre6\lib\rt.jar Logincontroller.java /MVCDemo/src/mvcdemo/controllers line 14 Java Problem
    HttpServlet cannot be resolved to a type Logincontroller.java /MVCDemo/src/mvcdemo/controllers line 16 Java Problem
    HttpServletRequest cannot be resolved to a type Logincontroller.java /MVCDemo/src/mvcdemo/controllers line 23 Java Problem
    HttpServletResponse cannot be resolved to a type Logincontroller.java /MVCDemo/src/mvcdemo/controllers line 24 Java Problem
    RequestDispatcher cannot be resolved to a type Logincontroller.java /MVCDemo/src/mvcdemo/controllers line 28 Java Problem
    ServletException cannot be resolved to a type Logincontroller.java /MVCDemo/src/mvcdemo/controllers line 24 Java Problem
    The import javax.servlet.http cannot be resolved Logincontroller.java /MVCDemo/src/mvcdemo/controllers line 7 Java Problem
    The import javax.servlet.http cannot be resolved Logincontroller.java /MVCDemo/src/mvcdemo/controllers line 8 Java Problem
    The import javax.servlet.http cannot be resolved Logincontroller.java /MVCDemo/src/mvcdemo/controllers line 9 Java Problem
    The import javax.servlet.RequestDispatcher cannot be resolved Logincontroller.java /MVCDemo/src/mvcdemo/controllers line 5 Java Problem
    The import javax.servlet.ServletException cannot be resolved Logincontroller.java /MVCDemo/src/mvcdemo/controllers line 6 Java Problem
    The public type LoginController must be defined in its own file Logincontroller.java /MVCDemo/src/mvcdemo/controllers line 16 Java Problem

    i have found this error in logincontroller plzz tell me how to solve this problem

    Reply
  • Pingback:Architecture Jsp Servlet | architects - residential architect

  • January 19, 2016 at 10:47 pm
    Permalink

    Good example but
    JSTL jar is not required for this example

    Reply
  • February 15, 2016 at 6:14 pm
    Permalink

    Nice example
    give me some more example
    with hibernet nn struts

    Reply
  • February 15, 2016 at 6:16 pm
    Permalink

    i have some problem in eclipse
    can you help me
    Several ports (2024, 4040, 8007) required by Tomcat v7.0 Server at localhost are already in use. The server may already be running in another process, or a system process may be using the port. To start this server you will need to stop the other process.
    how to solve this problem

    Reply
    • February 16, 2016 at 12:14 pm
      Permalink

      Hi Sachin, have you tried killing all the processes which are using these ports? Your tomcat is already running and you are again trying to start it that is why problem occurs.

      Reply
  • March 12, 2016 at 10:01 pm
    Permalink

    Thnku sir for this exp
    Give me exp of struts nd jsf

    Reply
  • March 22, 2016 at 5:32 pm
    Permalink

    Thank you Prasad

    Reply
  • March 22, 2016 at 5:34 pm
    Permalink

    Very good explanation sir

    Reply
  • April 2, 2016 at 12:53 pm
    Permalink

    Hi Prasad,

    I have just started learning MVC Architecture. You explanation was the simplest yet most beneficial to me. I did not understand half the things from my lectures and was getting so frustrated. I went thru so many sites on MVC your explanation was by far the best.

    However when i try to run login.jsp and enter the details I get the following error.
    type Status report

    message /MVCDemo/LoginController

    description The requested resource is not available.

    Thank you and bless you
    Usha

    Reply
    • April 2, 2016 at 3:34 pm
      Permalink

      Thank you Usha for kind words. Could you please let me know whether you are getting any exception in logs?

      Reply
      • April 5, 2016 at 12:07 pm
        Permalink

        Hi Prasad, it works now thanks for your help

        Reply
  • April 3, 2016 at 1:02 pm
    Permalink

    hi prasad, i like ur tutorial. i want ur help on struts framework with database (to manage emusic library.)

    Reply
    • April 3, 2016 at 10:19 pm
      Permalink

      Thank you for your words. Please let me know any problem you face. I will surely try to help.

      Reply
      • April 11, 2016 at 1:02 pm
        Permalink

        i want to know how can i manage my emusic library using struts framework.

        Reply
  • April 10, 2016 at 9:35 pm
    Permalink

    Hi Sir,
    I am getting the below error whenever i try to run the JSP page and enter the details. Can you please let me know what could be the root cause for this?


    HTTP Status 404 – /MVCDemo/LoginController

    ——————————————————————————–

    type Status report

    message /MVCDemo/LoginController

    description The requested resource is not available.

    ——————————————————————————–

    Apache Tomcat/7.0.56

    Reply
  • April 16, 2016 at 4:34 pm
    Permalink

    thanks for providing example sir

    Reply
  • April 23, 2016 at 1:58 am
    Permalink

    Very instructive and informative Tutorial. Another instructive example would be to show MVC pattern with regards to a NEW user registration.

    The reason this example would be beneficial is because it gives an opportunity to demonstrate the post/redirect/get pattern.

    Reply
  • July 26, 2016 at 10:59 am
    Permalink

    Please share the code of INSERT, UPDATE , and DELETE record as well, Thanks.

    Reply
  • July 26, 2016 at 6:00 pm
    Permalink

    Thnkew sir…bt can u plz tell me k user.java kb call hua???

    Reply
    • July 26, 2016 at 6:51 pm
      Permalink

      Thnkew…..sir…pta chl gya….

      Reply
  • August 1, 2016 at 8:15 pm
    Permalink

    Thank you Mr. Prasad for this helpful tutorial. I m a beginner in java and your explanation helped me a lot. Now things are quite clear than before. Please make some more tutorials on other j2EE/struts/hibernate topics.Thank you.

    Reply
    • October 5, 2016 at 5:56 pm
      Permalink

      hello mansi struts is out of market so don’t learn struts it is time waiste if you learn then go for spring framework is the best framework at that time,, in spring more jobs……….
      ye alag bat hai mujhe job nahi mili………………

      Reply
  • August 5, 2016 at 8:52 pm
    Permalink

    Programming is combination of intelligent and creative work. Programmers can do anything with code. The entire Programming tutorials that you mention here on this blog are awesome. also provides latest tutorials of Programming from beginning to advance level.
    Be with us to learn programming in new and creative way.

    Reply
  • August 29, 2016 at 11:48 am
    Permalink

    how to create a jar file in lib??

    Reply
  • October 5, 2016 at 9:04 am
    Permalink

    Can anybody will help me with library management system for book issuing function using MVC programming in JAVA and its database connectivity?

    Reply
    • October 5, 2016 at 9:14 am
      Permalink

      hi Snehal, Please show me what you have tried. I will be happy to help.

      Reply
  • October 5, 2016 at 5:49 pm
    Permalink

    Hello Sir
    My name is shilendra Tiwari i learnt servlet, jsp, jdbc, Spring, Hibernate, and also make 6 projects on servlet jsp but sir i have no job that time becoz sir at that time no vaicency came, Sir my english very veak,sir i want to know which place is more jobs in Spring Hibernate but english is not more mindatory i am very confused…………..

    Reply
  • January 18, 2017 at 7:14 pm
    Permalink

    nice explanation….now my thoughts so clear

    Reply
  • April 1, 2017 at 11:20 am
    Permalink

    Nice description of servlet and jsp with mvc

    Reply
  • April 3, 2017 at 7:25 pm
    Permalink

    Thank you Mr. Prasad Kharkar. Your post has helped me in understanding MVC better! Keep posting.

    Reply
  • April 12, 2017 at 7:34 pm
    Permalink

    sir i am getting 500 and 404 error to moving for next page

    Reply
  • April 14, 2017 at 10:35 pm
    Permalink

    I created a registration page where i need to insert data to database using servlets and in my registration page i have country and state where i need to fetch this data from database when ever i select a particular country only particular country states should display ..how do i pass to my jsp page using servlets

    Reply
  • July 15, 2017 at 12:56 pm
    Permalink

    Hi Sir,

    I’m getting an error in LoginController.java at “protected void (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{” as below

    Syntax error on token “void”, Identifier expected after this token

    Reply
  • August 11, 2017 at 7:25 pm
    Permalink

    where is the Model dude?

    Reply
  • September 8, 2017 at 7:08 pm
    Permalink

    Thanks for sharing Prasad!

    Reply
  • November 27, 2017 at 2:00 pm
    Permalink

    Hi Prasad give me code for jsp & Servlet mvc insert, update,delete operations with database.

    Fastly reply me. Thanks….

    Reply
  • November 30, 2017 at 2:20 pm
    Permalink

    Please give me code jsp & servlet mvc insert,update & delete code.
    Please fast reply me because my project regarding. Thanks….

    Reply
    • December 19, 2017 at 9:49 am
      Permalink

      Hi Hamid, are you facing certain problems in your project? I will be happy to solve any of your problems if you post here.

      Reply
  • December 2, 2017 at 9:56 am
    Permalink

    Please give me code for JSP & SERVLET MVC insert, update, & delete code
    One help me please

    Reply
    • December 19, 2017 at 9:45 am
      Permalink

      hi, could you please post the problem you are facing? Are you facing some error in your application ?

      Reply
  • January 25, 2018 at 5:29 pm
    Permalink

    It is very helpful for understanding MVC architecture with Jsp and Servlet.

    Reply
  • February 12, 2018 at 8:41 pm
    Permalink

    Hey Prasad what the purpose use of
    User user=new User() class.
    Why is need.

    Reply
  • February 12, 2018 at 8:44 pm
    Permalink

    Why use
    User user = new User(username, password);
    What is role this above code.

    Reply
  • March 14, 2018 at 11:59 am
    Permalink

    hi prasad,
    does this code work with tomcat 8???

    Reply
  • March 23, 2018 at 4:43 pm
    Permalink

    Hi ,
    can you please tell me what is model here in this example. i understood controller and view.
    Thanks

    Reply
  • April 19, 2018 at 5:29 pm
    Permalink

    Hi,
    it was great example but can you please explain why we use here POJO class or can you explain why we use pojo class in mvc based web application because,here I am not able to see any usage of it.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *