Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: How to display data from list into web browser with JSTL foreach loop ?

  1. #1
    Junior Member
    Join Date
    Oct 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to display data from list into web browser with JSTL foreach loop ?

    I know it's complicated enough that what I need but it is much more complicated to explain, but I'll try

    So I made a list of types <data> and fill some of the data. Now I have to in .jsp file using JSTL technology and with foreach loop display this data in a servlet (in a web browser).

    In JSTL file I tried to <c:forEach items="${ requestScope['newList'] }" var="data"> but I simply couldn't print anything in the browser.

    I'm interested if someone could help me and explain more in detail the above line, and also what command should be added to the servlet.

    Thank you!


  2. #2
    Member
    Join Date
    Nov 2011
    Posts
    37
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: How to display data from list into web browser with JSTL foreach loop ?

    Hi,
    Please modify your code as follow:
    <c:forEach items="${ requestScope.newList }" var="data">

    Core java
    Last edited by mr.miku; January 11th, 2012 at 07:10 PM.

  3. #3
    Junior Member
    Join Date
    Oct 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to display data from list into web browser with JSTL foreach loop ?

    Did, but still nothing. I think that problem is in my servlet. I'm sure that I did something wrong or didn't do something that I have to.

    here is the servlet code:

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub

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

    if(username.equals("student") && password.equals("password")){


    request.getSession().setAttribute("newList", Metoda.getGeneratedData());

    RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/WEB-INF/kupovina.jsp");
    dispatcher.forward(request, response);


    /*request.setAttribute("novaLista", Metoda.getGeneratedData());*/

    }
    else{
    final String rez = "Login failed! Try Again!";
    request.setAttribute("Rezultat", rez);
    RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/login.jsp");
    dispatcher.forward(request, response);
    }
    }

Similar Threads

  1. Need your help to display correct data by date
    By hanhtn in forum What's Wrong With My Code?
    Replies: 3
    Last Post: July 29th, 2011, 01:26 AM
  2. Random data out of a list.
    By arkaneraven in forum Java Theory & Questions
    Replies: 1
    Last Post: June 15th, 2011, 04:52 PM
  3. how can i display my data on jsp page in struts2
    By shekhar16 in forum Web Frameworks
    Replies: 0
    Last Post: March 4th, 2011, 06:26 AM
  4. Spreadsheet data - linked list or hashmap
    By j919 in forum Collections and Generics
    Replies: 2
    Last Post: February 19th, 2011, 06:04 PM
  5. saving list of data from JSP into java object
    By nrao in forum JavaServer Pages: JSP & JSTL
    Replies: 4
    Last Post: January 12th, 2011, 11:24 AM