gpt4 book ai didi

mysql - glassfish 4 & MySQL & JSTL

转载 作者:行者123 更新时间:2023-11-29 08:27:58 24 4
gpt4 key购买 nike

我正在使用 Netbeanse 7.3.1 + Glassfish 4。我使用 JSTL 编写了简单的 Web 应用程序

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>

<sql:query var="txt" dataSource="jdbc/mrm_db">
SELECT * FROM T2
</sql:query>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<table>
<c:forEach var="row" items="${txt.rows}">
<tr><td><c:out value="${row.txt}"/></td></tr>
</c:forEach>
</table>
</body>
</html>

我还添加了 Galssfish JDBC 资源并配置了连接池和 JDBC 资源。添加了 web.xml 和配置资源引用。

当我尝试启动我的应用程序时出现错误

Type Exception report

messageInternal Server Error

descriptionThe server encountered an internal error that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: javax.servlet.jsp.JspException: Unable to get connection, DataSource invalid: "java.sql.SQLException: Error in allocating a connection. Cause: Connection could not be allocated because: java.net.ConnectException : Error connecting to server localhost on port 1527 with message Connection refused."

root cause

javax.servlet.jsp.JspException: Unable to get connection, DataSource invalid: "java.sql.SQLException: Error in allocating a connection. Cause: Connection could not be allocated because: java.net.ConnectException : Error connecting to server localhost on port 1527 with message Connection refused."

note The full stack traces of the exception and its root causes are available in the GlassFish Server Open Source Edition 4.0 logs.

看起来 Glassfish 尝试使用 jdbc/__default,但不是我的数据源。

如果我在 Netbeans 7.2 和 Glassfish 3.2 中创建此项目,则可以正常工作。

你能帮帮我吗,我做错了什么?

谢谢!

最佳答案

在您的 web.xml 中包含以下资源定义,它应该可以正常工作。

<resource-ref>
<res-ref-name>jdbc/SOMETHING</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<mapped-name>jdbc/SOMETHING</mapped-name>
</resource-ref>

关于mysql - glassfish 4 & MySQL & JSTL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17427640/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com