英文:
JavaWeb java.lang.NoClassDefFoundError: sun/security/ssl/HelloExtension
问题
我在尝试使用Glassfish 5.0运行JavaWeb项目时遇到了错误。每次它试图从我的SQL数据库中获取数据时,都会出现以下错误。 <br>
StandardWrapperValve[ListadoPersonas]: Servlet.service() for servlet ListadoPersonas threw exception
java.lang.NoClassDefFoundError: sun/security/ssl/HelloExtension
以下是调用从数据库获取数据的函数的servlet ListadoEstadosCiviles
:
GestorPersonas g = new GestorPersonas();
ArrayList<EstadoCivil> lista = g.obtenerEstadosCiviles();
for (EstadoCivil estadoCivil : lista) {
out.println("<tr><td>" + estadoCivil.getId() + "</td><td>" + estadoCivil.getNombre() + "</td></tr>");
}
以下是GestorPersonas()
构造函数:
public GestorPersonas() {
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
} catch (ClassNotFoundException ex) {
Logger.getLogger(GestorPersonas.class.getName()).log(Level.SEVERE, null, ex);
}
}
以下是obtenerEstadosCiviles()
方法:
public ArrayList<EstadoCivil> obtenerEstadosCiviles() {
ArrayList<EstadoCivil> lista = new ArrayList<>();
try {
Connection conn = DriverManager.getConnection(CONN,USER,PASS);
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery("select * from EstadosCiviles");
// 如果select语句只返回一行记录,使用if而不是while
while (rs.next()) {
int id = rs.getInt("id");
String nombre = rs.getString("nombre");
EstadoCivil ec = new EstadoCivil(id, nombre);
lista.add(ec);
}
rs.close();
st.close();
conn.close();
} catch (SQLException ex) {
Logger.getLogger(GestorPersonas.class.getName()).log(Level.SEVERE, null, ex);
}
return lista;
}
我没有问题将我的Java应用程序连接到SQL,我认为问题出在Glassfish上,但我无法弄清楚为什么它不起作用。
这是调用obtenerEstadosCiviles()
函数的servlet,我期望表中充满数据。
更新
我刚刚检查了我的插件,发现Java Web和EE已经激活,但"Active"标志似乎没有激活。这可能是问题的一部分吗?
英文:
I'm getting an error when trying to use a JavaWeb project using Glassfish 5.0. Everytime it tries to bring data from my SQL Database it gives me this error. <br>
StandardWrapperValve[ListadoPersonas]: Servlet.service() for servlet ListadoPersonas threw exception
java.lang.NoClassDefFoundError: sun/security/ssl/HelloExtension
Here is the servlet ListadoEstadosCiviles
where I call the function which brings the data back from my database
GestorPersonas g = new GestorPersonas();
ArrayList<EstadoCivil> lista = g.obtenerEstadosCiviles();
for (EstadoCivil estadoCivil : lista) {
out.println("<tr><td>" + estadoCivil.getId() + "</td><td>" + estadoCivil.getNombre() + "</td></tr>");
}
Here is GestorPersonas()
constructor:
public GestorPersonas() {
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
} catch (ClassNotFoundException ex) {
Logger.getLogger(GestorPersonas.class.getName()).log(Level.SEVERE, null, ex);
}
}
Here is obtenerEstadosCiviles()
method
public ArrayList<EstadoCivil> obtenerEstadosCiviles() {
ArrayList<EstadoCivil> lista = new ArrayList<>();
try {
Connection conn = DriverManager.getConnection(CONN,USER,PASS);
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery("select * from EstadosCiviles");
// Si el select devuelve una única fila, en lugar de while, se usa un if
while (rs.next()) {
int id = rs.getInt("id");
String nombre = rs.getString("nombre");
EstadoCivil ec = new EstadoCivil(id, nombre);
lista.add(ec);
}
rs.close();
st.close();
conn.close();
} catch (SQLException ex) {
Logger.getLogger(GestorPersonas.class.getName()).log(Level.SEVERE, null, ex);
}
return lista;
}
I have no problem connecting my java application to sql, I think the problem is with glassfish but i cant figure out why it is not working
This is the servlet that is calling obtenerEstadosCiviles()
function, I expect that table full with data
UPDATE
I've just checked my plugins and it appears that Java Web and EE it´s activated but the "Active" symbol doesnt appears active. Could this be part of the problem?
答案1
得分: 6
基本上是相同的问题,最终通过这个解决方案解决了。
在你的glassfish文件夹中,进入glassfish5/glassfish/modules/endorsed/目录,用WinRAR或你偏好的解压工具打开grizzly-npn-bootstrap.jar文件。
删除sun文件夹,然后尝试重新运行你的程序。
英文:
Had basically the same problem, eventually solved it with this solution here.
In your glassfish folder go to glassfish5/glassfish/modules/endorsed/ and open the grizzly-npn-bootstrap.jar file with winrar or your preferred unzipper.
Delete the sun folder and try running your program again.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论