0
<form method="post" action="paperEditQ.do">
                Please select the subject you want to modify the database of :<select name="category">
                    <%
                        Statement st = DBConnection.DBConnection.DBConnect();
                        ResultSet rs = st.executeQuery("select * from papers");
                        while(rs.next()){
                            String paper = rs.getString(1);
                            out.print("<option>"+paper+"</option>");
                        }
                    %>        
                </select>
                <input type="submit" value="Modify"/>
</form>

This is the first page on my web application. I want to display the data from mySQL on this jsp page using jstl and EL tags (to get rid of the scriplets and strictly follow MVC). How would I do it? ( a little piece of code would really be appreciated).

Maverick
  • 302
  • 1
  • 5
  • 17
  • 1
    Put the elements from the `ResultSet` into a `List` or `Set` in a `Servlet` or struts `Action` and iterate over it with ``. – Sotirios Delimanolis Nov 29 '13 at 21:39
  • That's a really good idea. Do it, but not with Struts1, which is an obsolete, officially abandoned framework. Look at Spring MVC, Stripes, or Struts2 for example. Now, what's your question? – JB Nizet Nov 29 '13 at 21:40
  • I can't really learn a whole new framework overnight, that's another problem. – Maverick Nov 29 '13 at 21:41
  • @SotiriosDelimanolis can you write a little code so that I can get an idea. I thought i could do it without going to the controller. – Maverick Nov 29 '13 at 21:43
  • Not without getting rid of the scriplets. [Here's an example.](http://stackoverflow.com/questions/5893183/jstl-iterate-over-list-of-objects) – Sotirios Delimanolis Nov 29 '13 at 21:44
  • @SotiriosDelimanolis Can I create a dao class and then call it to display data from database? Because this page is accessed directly and does not flow from struts Action so I don't have a ResultSet to go with. – Maverick Nov 29 '13 at 22:06
  • @TheLiberal: the whole point of the MVC architecture promoted by Struts and all the other MVC frameworks is to never, never access a page directly, and to always go through a controller. Put your Java code in the controller, make it store Java beans in the request, and make your JSP generate HTML from those beans, using tags. – JB Nizet Nov 30 '13 at 07:34

1 Answers1

0

This topic shows some approaches to remove or minimize the use of code in jsp:

How to avoid Java code in JSP files?

Community
  • 1
  • 1
bcfurtado
  • 181
  • 2
  • 12