2017-05-18 1 views
0

모든 변수를 정의하고이 변수를 함수 본문의 다른 JSP 파일에서 사용하려는 JSP 파일이 하나 있지만 함수에서 Connection 변수를 사용할 때 변수를 찾을 수 없습니다 . 여기 좀 도와 줄 수있어?jsp의 다른 함수에서 Connection 변수 사용

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을 사용하는 것은 좋지 않습니다.

관련 문제