MVCモデル1個


目次

  • 目次
  • MVC 1ビン
  • 1.1従来のイタリア式コード
  • 1.2. MVC 1コード
  • References
  • 🎈≪接続ページ|Connection Page|Essbase_Studio≫-横にあるJSPの問題


    MVC 1ビン

  • detail.jsp
  • 1.1従来のイタリア式コード

    
    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <%
    String JDBC_URL = "jdbc:oracle:thin:@localhost:1521:XE";
    String JDBC_USER = "song";
    String JDBC_PW ="1234";
    String sql = "SELECT * FROM NOTICE";
    
    Class.forName("oracle.jdbc.driver.OracleDriver");
    Connection conn = DriverManager.getConnection(JDBC_URL, JDBC_USER, JDBC_PW);	
    PreparedStatement ps = conn.prepareStatement(sql);
    ResultSet rs = ps.executeQuery();
    
    %>
    
    <!DOCTYPE html>
    <html>
        <head>
        <title>MVC 1</title>
        </head>
        <body>
            <% while(rs.next()) { %>		             
                <tr>
                    <td><%=rs.getInt("ID") %></td>
                    <td class="title indent text-align-left"><a href="detail.jsp?id=<%=rs.getInt("ID")%>"><%= rs.getString("TITLE") %></a></td>
                    <td><%=rs.getString("WRITER_ID") %></td>
                    <td>
                        <%=rs.getDate("REGDATE") %>		
                    </td>
                    <td><%=rs.getInt("HIT") %></td>
                </tr>
                <% } %>
    
            <% 
            rs.close() 
            ps.close();
            conn.close();
            %>    	
        </body>
    </html>

    1.2. MVC 1コード

  • detail.jsp
  • 
    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
        
    <%
    
    int id = Integer.parseInt(request.getParameter("id"));
    
    String JDBC_URL = "jdbc:oracle:thin:@localhost:1521:XE";
    String JDBC_USER = "song";
    String JDBC_PW ="1234";
    String sql = "SELECT * FROM NOTICE WHERE ID=?";
    
    Class.forName("oracle.jdbc.driver.OracleDriver");
    Connection conn = DriverManager.getConnection(JDBC_URL, JDBC_USER, JDBC_PW);	
    PreparedStatement ps = conn.prepareStatement(sql);
    ps.setInt(1, id);
    
    ResultSet rs = ps.executeQuery();
    rs.next();
    
    String title = rs.getString("TITLE");
    Date regdate = rs.getDate("REGDATE");
    String writerId =  rs.getString("WRITER_ID");
    String hit = rs.getString("HIT");
    String files = rs.getString("FILES");
    String content = rs.getString("CONTENT");
    
    rs.close();
    ps.close();
    conn.close();
    
    
    %>
    
    <!DOCTYPE html>
    <html>
        <head>
        <title>MVC 1</title>
        </head>
        <body>
            <table class="table">
                <tbody>
                    <tr>
                        <th>제목</th>
                        <td><%=title %></td>
                    </tr>
                    <tr>
                        <th>작성일</th>
                        
                        <td><%=regdate %></td>
                    </tr>
                    <tr>
                        <th>작성자</th>
                        <td><%=writerId %></td>
                        <th>조회수</th>
                        <td><%=hit %></td>
                    </tr>
                    <tr>
                        <th>첨부파일</th>
                        <td><%=files %></td>
                    </tr>
                    <tr class="content">
                        <td><%=content %><div><br></div></td>
                    </tr>
                </tbody>
        </table>
        </body>
    </html>

    References

  • 新規編集 : Servlet / JSP
  • 🎈vscode定理
  • 🎈2021.01.01