玻璃鱼4& MySQL和JSTL [英] glassfish 4 & MySQL & JSTL
问题描述
我正在使用Netbeanse 7.3.1 + Glassfish4.我使用JSTL编写了简单的Web应用程序
I'm using Netbeanse 7.3.1 + Glassfish 4. I wrote simple web application using JSTL
<%@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>
我还添加了Galsfish JDBC资源,并配置了连接池和JDBC资源.添加了web.xml和配置资源引用.
Also i have added Galssfish JDBC Resource and configured connection pool and JDBC Resource. Added web.xml and config resource references.
当我尝试开始我的申请时,出现错误
And when i trying start my applicatio a get error
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,而不是我的数据源.
It's looks like that Glassfish try use jdbc/__default, but not my datasource.
如果我将这个项目创建到Netbeans 7.2和Glassfish 3.2中,就可以正常工作.
If i'm create this project into Netbeans 7.2 and Glassfish 3.2, it's work fine.
您能帮我吗,我在做什么错了?
Can you help me, what am i doing wrong?
谢谢!
推荐答案
在您的web.xml中包含以下资源定义,它应该可以正常工作.
Include the following resource definition in your web.xml and it should work properly.
<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>
这篇关于玻璃鱼4& MySQL和JSTL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!