繁体   English   中英

如何解决 Exception::java.security.AccessControlException: access denied in HttpServlet

[英]How to resolve Exception::java.security.AccessControlException: access denied in HttpServlet

我已经创建了一个 Servlet 类,我正在尝试从 Oracle 11g 中检索一条记录,并且我正在尝试使用 MySQL 数据库,但出现此异常:错误输出图像

我正在使用以下内容:

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 应用程序权限和操作。 只有目标平台的管理员可以帮助您(在运行策略中添加足够的授权,或者为您的目标提供替代方法)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM