Home News Conn是同级目录都在Tomcat\webapps\mywebapp文件夹中
a.jsp在文件夹Home中
b.jsp在文件夹News中
conn.jsp在文件夹Conn中
在a.jsp中引用conn.jsp写法为 <% include file= "../Conn/conn.jsp "%>
在b.jsp中引用a.jsp它就提示我找不到Home/../Conn/conn.jsp
我试了/Conn/conn.jsp 和 Conn/conn.jsp 都不行,请问我应该怎么引用啊???
------解决方案--------------------
把conn.jsp中的内容写到javabean中。直接在每个页调用。
package com.xxx.util;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;
public class DBUtil {
private Connection conn = null;
public DBUtil() {
try {
Context context = new InitialContext();
DataSource ds = (DataSource) (context.lookup( "java:comp/env/jdbc/xxx "));
this.conn = ds.getConnection();
} catch (Exception e) {
System.out.println( "取得数据库连接出错: "+e);
}
}
public Connection getConn() {
return this.conn;
}
public void close(){
try {
this.conn.close();
} catch (Exception e) {
System.out.println( "数据库关闭出错: "+e);
}
}
}
------解决方案--------------------
../Conn/conn.jsp 试试
------解决方案--------------------
把 <% include file= "../Conn/conn.jsp "%> 写为 <% include file= "/context/Conn/conn.jsp "%> 试试,其中的context是你的应用的context名