2017-05-18 26 views
0

我有一個jsp文件,我在其中定義了所有變量,並希望在函數體中的其他jsp文件中使用這些變量,但是當我在函數中使用Connection變量時,它說變量未找到。你能幫我嗎?在jsp的另一個函數中使用連接變量

a.jsp

Connection conn = null; 
conn = DriverManager.getConnection(Connecting_URL,DB_UserName,DB_Password); 

b.jsp

 <%@include file="a.jsp" %> 

     public static String user_exists (String email_id) throws Exception { 

      String SEARCH_SQL_COUNT = "SELECT COUNT(*) USER_COUNT FROM V_USER_DATA"; 
      PreparedStatement st_fetch_product_count_1 = conn.prepareStatement(SEARCH_SQL_COUNT); 
    ----- 
    -----  
return <string> 
    } 

回答

0

a.jsp:

request.setAttribute("connection", conn) 

b.jsp:

Connection conn = (Connection) request.getAttribute("connection") 

PS:

1 - 使用Scriptlet並不好,使用jsp taglib代替。 http://docs.oracle.com/javaee/5/tutorial/doc/bnake.html

2 - 在視圖層上使用SQL不是個好主意。

相關問題