0

I want to covert the scriptlet part into java classes.
Basically, there would be two classes consisting of the entity classes and the other class containing the method. The entity class contains all the table elements.

My main motive is to convert the scriptlet part into JAVA class.Here is what I have so far:
<%@page import="java.sql.*"%>
<%@page import="connection.Dbconnect"%>
<%@page session="true" %>

<div id="page" class="container">
    <div id="content">
        <%  
            String user = session.getAttribute("username").toString();
            ResultSet rs=null;
            ResultSet rs1=null;
            String s1,s2,s3,s4,s5,s6,s7;

            try{    
                Connection con=Dbconnect.getconnection();
                Statement st = con.createStatement();
                Statement st2 = con.createStatement();
                rs=st.executeQuery("select * from user where user_name = '"+user+"'");

                if ( rs.next() ){
                    s1 = rs.getString(1);
                    s2 = rs.getString(2);
                    s3 = rs.getString(3);
                    s4 = rs.getString(4);
                    s5 = rs.getString(5);
                    s6 = rs.getString(6);
                    s7 = rs.getString(7);
        %>

        <div class="title">
            <h2> <%=s4%> </h2>
            <h2> My Issues</h2>  
            <span class="byline"><p><b><a href="assignissue.jsp" rel="nofollow">Assign Issues</a></b></p></span>
        </div>
        <div class= "spltable">
            <table border-bottom=1 align=center style="text-align:center">
                <thead>
                    <tr>
                        <th>Issue ID</th>
                         <th>Subject</th>
                         <th>Description</th>
                         <th>Department</th>
                         <th>Date</th>
                         <th>Status</th>
                     </tr>
                 </thead>
                 <tbody>
                     <%
                         rs1 = st2.executeQuery("select * from issue where user_id = '"+s5+"'");
                         while(rs1.next()){
                     %>
                             <tr>
                                 <td><%= rs1.getString(1) %></td>
                                 <td><%= rs1.getString(2) %></td>
                                 <td align="justify"><%= rs1.getString(3) %></td>
                                 <td><%= rs1.getString(10) %></td>
                                 <td><%= rs1.getString(14) %></td>
                                 <td><%= rs1.getString(7) %></td>
                            </tr>
                     <% } %>
                  </tbody>
             </table>
         </div>
      </div>
   </div>
</div>

        <%
                }
            }
            catch(Exception e) {
                out.println(e.getMessage());
            }

        %>     
pczeus
  • 7,709
  • 4
  • 36
  • 51
mayukhsroy
  • 141
  • 1
  • 1
  • 9

1 Answers1

2

It's not necessary spring MVC for that (and to learn Spring MVC would take much more time and maybe neither the case to use here, despite is good to build robust applications, not the case here for what I see.... ), you create the class containing the logic, then a Servlet class will pass the result set to the Jsp page, an example on how to pass data from the Servlet to the Jsp can be found here: https://www.geeksforgeeks.org/getattribute-passing-data-from-server-to-jsp/

D Bruno
  • 61
  • 2
  • This is so complicated. Can you give a simplier example. – mayukhsroy May 02 '20 at 18:17
  • what I suggested is the simplest approach using jsp and java, mainly is structuring the code according to the MVC pattern, simpler than that is to have all in the jsp as you currently have but is not a way to do if your application start to grow more than few pages.... to be honest if you think that what explained is complicated have a look at Spring MVC as suggested before and will see that that is more complex. If you are not bind to Java maybe you can use other technologies.... – D Bruno May 03 '20 at 20:43