0
  • using m1 .
  • using Eclipse.
  • connected database and tomcat successfully.

[enter image description here][1]

There are two errors. (It seems like one problems)

1. HTTP 404

-> I rechecked tomcat path, java version, and locations. but It still doesn't work.

2. Page load failed with error: The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.[enter image description here][3]

-> Some bloggers said info.plist should be revised. I revised info.plist like below but it doesn't work.

[enter image description here][4]

package product;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;



public class productMgr {
    public ArrayList<product> getProduct(int categoryID) throws SQLException, ClassNotFoundException {
        ArrayList<product> products = new ArrayList<>();
        Class.forName("com.mysql.jdbc.Driver");
        Connection conn = null;
        PreparedStatement stmt = null;
        ResultSet rs = null;
        
         try {

            String sql = "select * from product where categoryId = ?";

            
            String jdbcDriver = "**jdbc:mysql://address**";
            String dbUser = "**root**";
            String dbPwd = "**pw**";
        
            conn = DriverManager.getConnection(jdbcDriver, dbUser, dbPwd);
            stmt = conn.prepareStatement(sql);
            stmt.setInt(1, categoryID);
            rs = stmt.executeQuery();
            
            while(rs.next()) {
                String ProductID = rs.getString("productID");
                int CategoryID = rs.getInt("categoryID");
                String ProductName = rs.getString("productName");
                int Price = rs.getInt("price");
                int Amount = rs.getInt("amount"); 
                products.add(new product(ProductID, CategoryID, ProductName, Price, Amount));
            }
            return products;
            
        }catch (SQLException se) {
            throw new RuntimeException("A database error occured. " + se.getMessage());
        }catch (Exception e) {
            throw new RuntimeException("Exception: " + e.getMessage());
        } finally {
            if (rs != null) {
                try {
                    rs.close();
                } catch (SQLException se) {
                    se.printStackTrace(System.err);
                }
            }
            if (stmt != null) {
                try {
                    stmt.close();
                } catch (SQLException se) {
                    se.printStackTrace(System.err);
                }
            }
            if (conn != null) {
                try {
                    conn.close();
                } catch (Exception e) {
                    e.printStackTrace(System.err);
                }
            }
        }
    }

[1]: https://i.stack.imguenter code herer.com/Lo5t5.png [2]: https://i.stack.imgur.com/yxt4j.png [3]: https://i.stack.imgur.com/3SFJI.png [4]: https://i.stack.imgur.com/qDT3i.png

  • You are using Tomcat 10, which is a Jakarta EE 9 servlet container. Make sure that your servlets use the `jakarta.servlet` namespace instead of `javax.servlet`. For more details check, e.g. [this question](https://stackoverflow.com/q/64387472/11748454). – Piotr P. Karwasz May 30 '21 at 13:58
  • @ Piotr P. Karwasz Hi, Piotr P. Thank you for comments. I used tomcat9 instead of tomcat10, It doesn't work tho. :( – 호찌누나 May 31 '21 at 12:14
  • That wasn't the only problem: Tomcat will **never** serve the contents in the `WEB-INF` library, you JSP must be outside of this folder or must be called by a servlet. – Piotr P. Karwasz May 31 '21 at 13:53

0 Answers0