Results 1 to 16 of 16

Thread: Mvc

  1. #1
    tandonpiyush is offline Member
    Join Date
    May 2011
    Posts
    10
    Rep Power
    0

    Default Mvc

    i want to know how many controller and model files are there single web project of mvc architecture.

  2. #2
    Petr's Avatar
    Petr is offline Senior Member
    Join Date
    Jan 2011
    Location
    Russia
    Posts
    620
    Rep Power
    4

    Default

    It is strange questions. it depends from a project.
    MVC is only convenient approach for architectural app.
    For web app is used JSP as view, Servlet - as controller and POJO as model.
    Skype: petrarsentev
    http://TrackStudio.com

  3. #3
    tandonpiyush is offline Member
    Join Date
    May 2011
    Posts
    10
    Rep Power
    0

    Default

    Am asking do we make one action and only one model file??

  4. #4
    Petr's Avatar
    Petr is offline Senior Member
    Join Date
    Jan 2011
    Location
    Russia
    Posts
    620
    Rep Power
    4

    Default

    I can't parse your question. Can you elaborate more details?
    Skype: petrarsentev
    http://TrackStudio.com

  5. #5
    tandonpiyush is offline Member
    Join Date
    May 2011
    Posts
    10
    Rep Power
    0

    Default

    I want to create one application based on mvc architecture and as per same am representing my view with jsp pages, controller with servlet files, am bit confused about model files what do model files contains.

  6. #6
    Petr's Avatar
    Petr is offline Senior Member
    Join Date
    Jan 2011
    Location
    Russia
    Posts
    620
    Rep Power
    4

    Default

    Ok. For example you have table in database, which contain follows column
    Java Code:
    create table User (
        uid serial not null,
        ulogin text not null,
        upassword text not null,
        urole text not null,
        constraint pkUser PRIMARY KEY (uid)   
    )
    Then you make POJO class, It is model for MVC architecture.
    Java Code:
    public class User {
        private Integer id;
        private String login;
        private String password;
        private String role;
        //belov set/get methods. I don't wrote it for economic space.
    }
    Then you make DAO layer, Where you accomplish CRUP operations for your model User.
    Like this.
    Java Code:
    List<User> users = DAOLayer.getAllUsers();
    This operation you can make in Servlet. Then you pass this data in JSP. In JSP you use model User and data from servlet.
    Like this
    Java Code:
    <c:forEach items="${users}" var="user">
       <tr>
             <td><c:out value="user.login"/></td>
             <td><c:out value="user.role"/></td>
       </tr>
    </c:forEach>
    For powerful if you use some MVC frameworks. for instance Spring MVC, Struts or GWT (maybe you have experience in gui develop)
    Last edited by Petr; 05-15-2011 at 12:53 PM.
    Skype: petrarsentev
    http://TrackStudio.com

  7. #7
    tandonpiyush is offline Member
    Join Date
    May 2011
    Posts
    10
    Rep Power
    0

    Default

    u mean a model file is java bean??

    one thing more if i want to write connection string in which file i will write.can i write the same in servlet file or else?

    Action files are written in which i.e in servlet??

  8. #8
    Petr's Avatar
    Petr is offline Senior Member
    Join Date
    Jan 2011
    Location
    Russia
    Posts
    620
    Rep Power
    4

    Default

    What is mean "connection string"?
    look at that Combining Servlets, JSP, and JavaBeans
    Skype: petrarsentev
    http://TrackStudio.com

  9. #9
    tandonpiyush is offline Member
    Join Date
    May 2011
    Posts
    10
    Rep Power
    0

    Default

    connection string means db connectivity

  10. #10
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,015
    Rep Power
    20

    Default

    DB connections are usually handled in a database layer, in the form of DAOs for example.
    You don't handle database stuff inside your model.

  11. #11
    tandonpiyush is offline Member
    Join Date
    May 2011
    Posts
    10
    Rep Power
    0

    Default

    can anyone provide me detailed explanation of MVC architecture

  12. #12
    Petr's Avatar
    Petr is offline Senior Member
    Join Date
    Jan 2011
    Location
    Russia
    Posts
    620
    Rep Power
    4

    Default

    Did you read that article which I pointed in post above? I think you did not.
    That is detail elaborate all steps for create MVC architecture for app and provide a short example.
    if you don't want to figure out nobody will not help you.
    Skype: petrarsentev
    http://TrackStudio.com

  13. #13
    tandonpiyush is offline Member
    Join Date
    May 2011
    Posts
    10
    Rep Power
    0

    Default

    i hv read that but i hv doubt ..

    View is represented by JSp.
    Action is represented by Servlet.
    Model is represented by Bean.

    am i correct or not?

    in model file we establisg the connection to db and whr should we write query for fetching data from database. what should we write in action files

  14. #14
    Petr's Avatar
    Petr is offline Senior Member
    Join Date
    Jan 2011
    Location
    Russia
    Posts
    620
    Rep Power
    4

    Default

    View is represented by JSp.
    Action is represented by Servlet.
    Model is represented by Bean.
    This is correct. but other is wrong.
    For connecting to database you create special layer. Where you get data from database and fulling list which contain model data.
    for instance
    Java Code:
    List<Order> ords = KM.getOrder().getOrdersByStatus(Order.Status.STATUS_INIT);
    request.setAttribute("orders", ords);
    RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(request.getContextPath() + "/Admin/Orders/QueueInnerTable.jsp");
    dispatcher.forward(request, response);
    Where KM.getOrder().getOrdersByStatus - this method locate in DAO layer.
    Skype: petrarsentev
    http://TrackStudio.com

  15. #15
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,015
    Rep Power
    20

    Default

    The reason for having a separate layer for getting the data is (if written as interfaces) that you can replace the database stuff with, say, a flat file system of persisting the data, or web service calls instead.

  16. #16
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,244
    Rep Power
    19

    Default

    Quote Originally Posted by tandonpiyush View Post
    i hv read that but i hv doubt ..
    Learn to write well before you tackle Java or programming.

    db

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •