你的问题没描述清楚嘛....
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 可获得这些配置。
解决方案 »
- struts2 spring3.2 hibernate4.1.9 整合No Session found for current thread
- 在线等 s:iterator 迭代 list<user> 获取不了值
- 图文混排文章的数据库保存
- 怎么能不让hibernate报错啊???
- session可以做到的,用hibernateTemplate如何做到?
- struts2与sitemesh的一个问题
- 初学spring,兄弟们帮帮忙出注意了
- java网络编程问题。
- [急]apache的URL转发控制问题
- 求助:我的struts应用中有一个action,每隔1至两个小时
- 难到这是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");