Results 1 to 4 of 4

Thread: Spring bean data access in page when first loads using JSTL

  1. #1
    Join Date
    Sep 2009
    Posts
    12

    Default Spring bean data access in page when first loads using JSTL

    Hi all,

    I have a little problem, I have a data input page(.jsp page). In my application this page is the index page(When application begins, this loads first). This gives some text fields to enter data and some questions to be answered by a user.

    These questions are inside questions table and I have entity class for it. I wish to write DAO class and DAO implementation class for it.

    What I want to do is, When this index page loads, those all questions should be loaded to the page. I don't want to write any sql queries in my jsp pages. SQLs will be in DAO classes.

    If this can be done by using JSTL, it will be very useful. but I don't know how to do this.

    I don't know how to get appropriate bean inside my index page.

    If anyone know, Please let me know...

    regards,
    Dilan.

  2. #2
    Join Date
    Jul 2009
    Location
    PUNE
    Posts
    43

    Post RE:Spring bean data access in page when first loads using JSTL

    Hello,

    You need to use spring mvc to achieve this. The steps for this are:

    1. Write a java bean representing the data you want to display on the web page.
    2. Write a DAO to manage the CRUD operations. The finder's in this DAO will return the bean instance or bean instance(s) via a list.
    3. Write a java class derived from AbstractFormController override processFormSubmission, showForm(HttpServletRequest request, HttpServletResponse response, BindException errors) and referenceData(HttpServletRequest request, Object command, Errors errors) throws Exception. YThe first method in your bean is used to procss the form submissions. The second is typically used to populate the bean instance and the last method is used to populate a map with additional data that may not be part of the form bean.
    4. Write the xxxx-servlet.xml file containing the mvc mapping of controller against the action. Here specify the command class as the full name of the bean you have created in strp 1. Also supply a value to commandName parameter. This name will be used in JSP page to access the methods of the bean.
    5. Create a JSP and use spring's form tag library to bind the data to form elements. You can also use JSTL here but I suggest to use the former.


    SO if your commadName is say model and the bean has a getter method named say getDescription then you can access this method in JSTL using
    Code:
    <c:out value="${model.description}"/>
    .

    Hope this solves your problem. I will also recommend to vist the http://www.springbyexample.org/ site to see some good examples.

    Regards,
    Prasad P. Khandekar

  3. #3
    Join Date
    Apr 2008
    Posts
    13

    Smile

    In my opinion,the index page of a website should be very fast for visiting users.So my advice is to static the index page.Our company's home page is staticed to a jsp page,very fast for users(addawow.com). Spring + Velocity can do this!

  4. #4
    Join Date
    Sep 2009
    Posts
    12

    Default

    Really appreciate this help, this is what i want. Ill check this one and let know the result.

    regards,
    Dil.

Posting Permissions

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