我创建了一个Servlet类,并尝试从Oracle 11g中检索一条记录,并且尝试使用MySQL数据库,但遇到了以下异常:error ouput image

我正在使用以下内容:

WebServer: Tomcat9
JRE: 1.8
Databases: Oracle 11g,MySQL


这是我的servlet类:

public class EmployeeSearchApp extends HttpServlet{

    private static final String EMP_SEARCH_DETAILS = "SELECT EMPMO,ENAME,JOB,SAL,EMPNO FROM EMP WHERE EMPNO=?";

      private static final String url="jdbc:oracle:thin:@localhost:1521:orcl";
      private static final String userName = "scott";
      private static final String password = "tiger";
    /*
     * private static final String url="jdbc:mysql://localhost:3306/world"; private
     * static final String userName = "ram"; private static final String password =
     * "padma";
     */

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
        PrintWriter pw=null;
        int eno=0;
        Connection con=null;
        PreparedStatement ps=null;
        ResultSet rs=null;
        try {
            //Getting the print Writer Object
            pw=res.getWriter();

            //Setting the content type
            res.setContentType("text/html");

            //getting the parameter value
            eno=Integer.parseInt(req.getParameter("eno"));

            //JDBC code

            //Registering JDBC driver
            Class.forName("oracle.jdbc.driver.OracleDriver");
            //Class.forName("com.mysql.jdbc.Driver");

            //Establishing the db connection
            con=DriverManager.getConnection(url,userName,password);

            //Preparing the Prepared Statement object
            ps=con.prepareStatement(EMP_SEARCH_DETAILS);

            //set the value into query param
            ps.setInt(1, eno);

            //execute the sql query
            rs=ps.executeQuery();

            //process the result set object
            if(rs.next()) {
                pw.println("<h1>EMPLOYEE DETAILS</h1>");
                pw.println("<h1>Employee ID:"+rs.getInt(1)+"</h1>");
                pw.println("<h1>Employee Name:"+rs.getString(2)+"</h1>");
                pw.println("<h1>Employee Job:"+rs.getString(3)+"</h1>");
                pw.println("<h1>Employee Sal:"+rs.getDouble(4)+"</h1>");
                pw.println("<h1>Employee Dept NO:"+rs.getInt(5)+"</h1>");
            }

        }catch (SQLException se) {
            se.printStackTrace();
            pw.println("<h1 style='color:red;'>Internal Database problem</h1>");
        }
        catch (ClassNotFoundException cnf) {
            cnf.printStackTrace();
            pw.println("<h1 style='color:red;'>Internal problem</h1>");
        }

        catch (Exception e) {
            e.printStackTrace();
            pw.println("<h1 style='color:red;'>Internal problem</h1>");
        }finally {
            rs.close();
            ps.close();
            con.close();
        }
    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
        doGet(req, res);
    }
}



控制台上的异常如下

Exception::java.security.AccessControlException: access denied


一个人可能会遇到这种异常的情况可能是什么?
而我该如何解决呢?

最佳答案

堆栈跟踪显示安全管理器(即Java策略)已启用,并限制您访问系统属性。
这意味着您的JVM / Tomcat已配置为限制Web应用程序特权和操作。只有目标平台的管理员才能为您提供帮助(在运行策略中添加足够的授权,或者为您提供针对目标的替代方法)。

关于java - 如何解决Exception::java.security.AccessControlException:HttpServlet中的访问被拒绝,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/60799288/

10-11 22:08
查看更多