[英]How to resolve Exception::java.security.AccessControlException: access denied in HttpServlet
I have created one Servlet class and I am trying to retrieve one record from Oracle 11g and also I am trying to use MySQL database but getting this exception: error ouput image我已经创建了一个 Servlet 类,我正在尝试从 Oracle 11g 中检索一条记录,并且我正在尝试使用 MySQL 数据库,但出现此异常:错误输出图像
I am using below stuff:我正在使用以下内容:
WebServer: Tomcat9
JRE: 1.8
Databases: Oracle 11g,MySQL
Here is my servlet class:这是我的 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);
}
}
and the exception on console is as follows控制台上的异常如下
Exception::java.security.AccessControlException: access denied
What could be the possible scenarios when one may get this exception?当一个人可能会遇到此异常时,可能的情况是什么? And how do I resolve this?
我该如何解决这个问题?
Stack-trace shows that a security manager (ie: java policies ) is enabled, and restraining you from accessing system properties.堆栈跟踪显示启用了安全管理器(即: java 策略),并限制您访问系统属性。 That means that your JVM/Tomcat has been configured to restrain web application privileges and actions.
这意味着您的 JVM/Tomcat 已配置为限制 Web 应用程序权限和操作。 Only the administrator of the target platform can help you with that (either add sufficient authorizations in running policies, or give you an alternative method for what you aim for).
只有目标平台的管理员可以帮助您(在运行策略中添加足够的授权,或者为您的目标提供替代方法)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.