Jsp pages in the documents obtained absolute path

  Abstract: In the jsp page document obtained absolute path 

  </ Td> </ tr> <tr> <td height="35" valign="top" class="ArticleTeitle"> If we cwb.mdb database files (or other resources picture, sound) on the d: \ Tomcat 5.0 \ webapps \ WEB-INF \ Below, 
  Well, jsp pages can connect to: 
  String strurl = "jdbc: odbc: driver = (Microsoft Access Driver (*. mdb)); DBQ = D: \ \ Tomcat 5.0 \ \ webapps \ \ zz3zcwbwebhome \ \ WEB-INF \ \ cwb.mdb"; 
  But this will be the path hard-coded resources in the code, once we have the WEB application move, or change directory, we will have to look for these resources include all jsp to change path.    Solution is added directly to each of WEB application to / URL prior to the start.    This is not hard-coded name.    But the use of getServletContext (). GetRealPath ("/") methods identified in the implementation of this title. 
  <% @ Page contentType = "text / html; GBK charset ="%> 
  <% @ Page language = "java" import = "java.sql .*"%> 
  <table Width="722" height="32" border="0"> <tr> <td width="454"> <% 
  String aa = getServletContext (). GetRealPath ("/")+" WEB-INF \ \ cwb.mdb "; 
  String strurl = "jdbc: odbc: driver = (Microsoft Access Driver (*. mdb)); DBQ =" + aa; 
  Out.println ( "path =" + + strurl " 
");
  Class.forName ( "sun.jdbc.odbc.JdbcOdbcDriver"); 
  Connection conn = DriverManager.getConnection (strurl); 
  Statement stmt = conn.createStatement (); 
  ResultSet rs = stmt.executeQuery ( "select * from Article"); 
  If (rs.next ()) 
  Out.println ( "OK! Size =" + rs.getString ( "Article_size")); 
  Rs.close (); 
  Stmt.close (); 
  Conn.close (); 

%>
  </ Td> <td width="258"> </ td> </ tr> </ table> 

  </ Td> </ tr> <tr> 

  ↑ Back 

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Facebook
  • DotNetKicks
  • DZone
  • Netvouz
  • Propeller

Tags:

Releated Java Articles

Comments

Leave a Reply