jsp JNDI
来源:互联网 发布:管家婆软件使用教程 编辑:程序博客网 时间:2024/06/09 17:41
统一的接口
对象和名字绑定的技术,分布式系统中访问其它组件和资源,如dns,file service db
WEB 容器
1.context.xml
<Environment name="tjndi" value="hello jndi" type="java.lang.String" />
2.jsp
<%
//javax.naming,Context提供了查找jndi resource的接口
Context ctx = new InitialContext();
//java:comp/env为前缀
String textjndi = (String) ctx.lookup("java:comp/env/tjndi");
out.print("textjndi:" +" "+ textjndi);
//
%>
ds
WEB 容器
1.context.xml
<!-- dataSource and jndi auth="Applicantion"-->
<Resource name="jdbc/orcl" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000" username="scott"
password="tiger" driverClassName="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:@localhost:1521:orcl" />
WEB app web.xml
2.
<resource-ref>
<description>orcl ds</description>
<res-ref-name>jdbc/orcl</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
3.jsp
<%
Context cxt = new InitialContext();
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
DataSource ds = (DataSource) cxt
.lookup("java:comp/env/jdbc/orcl");
con = ds.getConnection();
ps = con.prepareStatement("select * from emp e where ename = ? ");
ps.setString(1, "SMITH");
rs = ps.executeQuery();
if (rs.next()) {
out.print("登录成功 ");
}else{
out.print("login faild");
}
} catch (Exception e) {
out.println(e);
} finally {
try {
if (rs != null) {
rs.close();
}
if (ps != null) {
ps.close();
}
if (con != null) {
con.close();
}
} catch (Exception ex) {
out.print(ex);
}
}
%>
- jsp JNDI
- JSP + Jndi + Spring + Hibernate组合
- JNDI获取数据源实例(jsp)
- 在jsp中进行JNDI数据源调试
- JNDI
- JNDI
- jndi
- JNDI
- JNDI~~~~
- JNDI
- JNDI
- JNDI
- JNDI
- JNDI
- JNDI
- JNDI
- JNDI
- jndi
- HDU 2093
- JSP学习知识笔记
- 从贝叶斯方法谈到贝叶斯网络
- HDU 1302 The Snail(模拟题)
- java web笔记——服务器端防刷新页面重复提交表单
- jsp JNDI
- sublime的安装
- spring+springmc+mybatis整合遇见的问题
- C++ 语法知识 3
- 4月27号全国高校云计算大赛晋级
- Equidivisions
- HDU 1054 Hungary
- hdu-4544-湫湫系列故事——消灭兔子-贪心+stl
- 看过的一些iOS书籍及源代码下载地址