你的问题没描述清楚嘛....
web.xml不是你来读取的,而是servelt engine,我不建议你用自己编写的程序来查找web.xml.你可以通过配置在web.xml中设置相关的servelt 参数
然后在 servelt中可以根据servelt config、context 可获得这些配置。
web.xml不是你来读取的,而是servelt engine,我不建议你用自己编写的程序来查找web.xml.你可以通过配置在web.xml中设置相关的servelt 参数
然后在 servelt中可以根据servelt config、context 可获得这些配置。
解决方案 »
- 怎么用正则表达式截取字符串,急!!!
- 各位大虾,请问IE关闭时弹出“确认离开该页面”的信息,如何取消掉?
- 请问如何用itext读取pdf模板后 在模板需要的位置添加上一个表格呢?
- http的post或get方式发送xml文件
- 提交到一个servlet 想执行2次查询SQL语句 取不同的值 如何实现??
- 求教高手!不识别Struts2标签!
- 求助帖 JAVA程序运行时JList中内容动态显示过程中有时候消失的问题
- 求助!swing中有几种open source架构!
- weblogic7连sqlserver 2000出错!请高手帮忙!
- 寻找好的介绍EJB的书,高分酬谢
- 难到这是Hibernate的bug
- 在eclipse中连接oracle 数据库时出现,出现the Network Adapter could not establish the connection
<DBDriver>com.microsoft.jdbc.sqlserver.SQLServerDriver</DBDriver>
<DBUrl>jdbc:microsoft:sqlserver://172.18.1.3:1433;DatabaseName=P;SelectMethod=Cursor</DBUrl>
<user>sa</user>
<password></password>
</DBServer>这个是我在web.xml中写的连接字符串的数据 楼上的大哥能不能给各例子什么的阿
我刚刚接触java 好头疼阿 谢谢了阿
在web-inf目录建一个jdbc.properties文件,然后在里面加入你的参数
dbdriver=com.microsoft.jdbc.sqlserver.SQLServerDriver
dburl=jdbc:microsoft:sqlserver://172.18.1.3:1433;DatabaseName=P;SelectMethod=Cursor
user=sa
password=
在servlet中,你可以这样来读取
String syspath = request.getSession().getServletContext().getRealPath("");
FileInputStream fin = new FileInputStream(syspath+"/WEB-INF/jdbc.properties");
Properties prop = new Properties();
prop.load(fin);
String dbdriver = prop.getProperty("dbdriver");
String dburl = prop.getProperty("dburl");
String user = prop.getProperty("user");
String password = prop.getProperty("password");
System.out.println(dbdriver+" "+dburl+" "+user+" "+password);
建议不要自己去读web.xml里面的参数,web服务器会帮你读的
配个数据源就得了,为啥还要这样,服务器会自动加栽这些东西。干吗还要手动的得到呢
--------------
有道理,你打算自已写连接池吗?
<context-param>
<param-name>dbdriver</param-name>
<param-value>com.microsoft.jdbc.sqlserver.SQLServerDriver</param-value>
</context-param>
<context-param>
<param-name>dburl</param-name>
<param-value>jdbc:microsoft:sqlserver://172.18.1.3:1433;DatabaseName=P;SelectMethod=Cursor</param-value>
</context-param>
<context-param>
<param-name>user</param-name>
<param-value>sa</param-value>
</context-param>
<context-param>
<param-name>password</param-name>
<param-value></param-value>
</context-param>在对应的servlet的service方法中这样一来取
ServletContext sc = getServletConfig().getServletContext();
String strDBDriver = sc.getInitParameter("dbdriver");
String strDBUrl = sc.getInitParameter("dburl");
String strDBUser = sc.getInitParameter("user");
String strDBPassword = sc.getInitParameter("password");