0

So I'm trying to make a page that goes into a database and then prints out every result in the resultset as a row in a table. I have it working, but the style is horrible (first time using jsp and just wanted it to function first - all java code is in the jsp file). I know servlets shouldn't be in the jsp for style (or that's what I read...), but it's hard finding an example that follows that rule and helps me understand how the jsp and java file are linked.

So if I have a for loop that assigns a variable "var" based on a result from a resultset, how exactly would I call that from a jsp file? I know there's something like

    <c:forEach items="${var}" var="result">
      ${result.name}
      ${result.rate}
    </c:forEach>

But when I made a small test file, I was getting an error saying c was an unknown tag, so I'm not sure how to resolve that. I'm also not sure how to link the jsp file to the java file so that the function in the file runs and the jsp page knows what ${var} is. Is there supposed to be something in my web.xml file? Any help would be great. Just so great.

  • *I know servlets shouldn't be in the jsp for style (or that's what I read...), but it's hard finding an example that follows that rule and helps me understand how the jsp and java file are linked* There's a good example in [our Servlets wiki](http://stackoverflow.com/tags/servlets/info) – Luiggi Mendoza Apr 30 '15 at 19:44

1 Answers1

0

you can use spring MVC as follow in the Spring controller get you data from the DB and put it in the ModelAndView Object and pass it to the view in the view you can do some thing I assume you create ModelAndView mav; and then do this line of code

mav.add("DB_LIST" , yourdateModel) ; 

<c:forEach items="${var}" var="${DB_LIST}">
      ${result.name}
      ${result.rate}
    </c:forEach>

this following is good example http://www.journaldev.com/3531/spring-mvc-hibernate-mysql-integration-crud-example-tutorial

also many other framework available for you such as Strut2, Struts1

Alaa Abuzaghleh
  • 1,023
  • 6
  • 11