导航:首页 > 文件教程 > web获取配置文件

web获取配置文件

发布时间:2023-03-24 14:42:12

① ASP.NET MVC 4中如何读取web.config中的配置

用ConfigurationManager这个类。

② web项目中如何读取配置文件config.xml

servlet初始化的时候会去读取web.xml,把这个文件的路径配置到web.xml里。或者你在web.xml里加载个初始化类,这个类去加载config.xml

③ 为什么就是获取不到javaweb工程下的配置文件所在路径

在Java web项目中经常会用属性文件作为配置文件,而其一般放在src的根目录下,读取文件时一般会有以下两种情况:

方式一、在servlet中读取:

// action配置文件路径
public static final String ACTIONPATH = "WEB-INF/classes/actions.properties";
// 属性文件
public static final Properties prop = new Properties();
// 获取servlet上下文的绝对路径,如:C:\Program Files\Apache\Tomcat 6.0\webapps\fee\
String path = getServletContext().getRealPath("\\");
// 把文件读入文件输入流,存入内存中
FileInputStream fis = new FileInputStream(new File(path + ACTIONPATH));
//加载文件流的属性
prop.load(fis);
方式二、在一般的类中读取:
// action配置文件路径
public static final String ACTIONPATH = "actions.properties";
// 属性文件
public static final Properties prop = new Properties();
// 获取当前类加载的根目录,如:/C:/Program Files/Apache/Tomcat 6.0/webapps/fee/WEB-INF/classes/
String path = UriFilter.class.getClassLoader().getResource("").toURI().getPath();
// 把文件读入文件输入流,存入内存中
FileInputStream fis = new FileInputStream(new File(path + ACTIONPATH));
//加载文件流的属性
prop.load(fis);

④ webpack打包VUE项目读取外部配置文件,灵活配置域名

1.在index.html中引入js
<script src="./static/config.js"></script>
2.man.js

⑤ java web工程,读取配置文件路径问题

读取复src下的文制件,可以用下面的方式

publicclassTest1{

publicstaticvoidmain(String[]args){
Propertiespro=newProperties();
InputStreamin=Test1.class.getResourceAsStream("/config.properties");
try{
pro.load(in);
pro.getProperty("aa");
}catch(IOExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}
}
}

⑥ web.xml中如何读取properties配置文件中的值

方法如下:

<context-param>


<param-name>log4jConfigLocation</param-name>


<param-value>classpath:/config/log4j.properties</param-value>


</context-param>

⑦ JAVA maven创建web把Spring放在src/main/读取不到配置文件是怎么回事

classpath:是从类路径里查找配置文件,也就是/WEB-INF/classes目录下找SpringMVC-servlet.xml。

你写了classpath了,不会从web-info下找,而是去web-inf/classes下面找,所以找不到。

⑧ myeclipse做webservice开发,如何读取配置文件中web.xml中设置的参数

给个小例子参考参考~~~

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class Loginv1Servlet extends HttpServlet {
private String xmlName,xmlPass;
protected void doGet(HttpServletRequest arg0, HttpServletResponse arg1)
throws ServletException, IOException {

doPost(arg0, arg1);
}

public void init(ServletConfig config) throws ServletException {
// 初始化时候对xml文档的内容进行读取 //这个是重写超类方法
xmlName=config.getInitParameter("name");
xmlPass=config.getInitParameter("pass");

/*
* <init-param>

* <param-name>pass</param-name>

* <param-value>123456</param-value>

*xml文件中的写法,写在<servlet> 块内
* </init-param>
*/

}
protected void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
//首先对客户端的数据流编码 解决中文问题
req.setCharacterEncoding("GB2312");
// 得到客户传递的数据

String str= req.getParameter("action");
String id=req.getParameter("id");
String name=req.getParameter("name");
String amount=req.getParameter("amount");
res.setContentType("text/html;charset=gb2312");
PrintWriter pw=res.getWriter();
pw.println("<html>");
pw.println("<title>准备购买的商品信息</title><body>");
pw.println("编号:"+ id);
pw.println("名称:"+ name);
pw.println("数量:"+ amount);

if("1".equals(str)){
//电子支付
pw.println("<a href='http://www.post.com.cn'target=_blank> 进入网上银行</a>");
}else{
//汇款
pw.println("<a href='info.html'>填写详细信息</a>");
}
pw.println("</body>");
pw.println("</html>");

}

}

⑨ java web项目 web.xml中如何读取properties配置文件中的值

<util:properties id="config" location="classpath:test.properties" />
其中id为读取文件以后的bean id,可以通过这个id获取文件中对应属性的值,如config.test代表获取文件中test属性的值

⑩ java 怎么读取web jar中的某个配置文件

项目迁移的过程中发现以前的代码维护性实在是差。
我把问题简化为以下这专些简单的代码:属
项目M
引用了项目
A.jar,这个A在lib目录里面
在A里面放置了一个配置文件test.properties,
就放在jar的根目录下。
A.jar
|___test.properties
在M中有一段代码回去读取这个A.jar里的配置文件,简单一点就用下面这句话来调用。
Java
code
public
class
ConfigUtil
{
public
static
String
getInstance()
throws
Exception{
String
path
=
ConfigUtil.class.getResource("/").toString();
path
=
path.substring(0,
path.length()-8);//
System.out.println(path);//这里打印的结果显示可以拿到当前类的绝对路径
InputStream
f
=
new
FileInputStream("jar:"+path+"lib!/A.jar/"+"test.properties");
return
"xxx";
}
}

阅读全文

与web获取配置文件相关的资料

热点内容
网络传输介质的选择 浏览:253
fpga设计教程pdf 浏览:352
在哪个网站学数据库 浏览:705
jsp中包含外部文件的方式 浏览:179
applewatch打电话功能 浏览:73
编程中无法载入图片是怎么回事 浏览:487
房地产采购库有哪些网站 浏览:450
文件名添加斜杠 浏览:645
java上传文件到linux转码 浏览:243
sel文件如何转成excel 浏览:942
汽车微信广告语 浏览:931
单精度浮点数据怎么算 浏览:609
网络营销论文怎么写 浏览:326
在编程语言中函数是什么 浏览:516
开票软件金税盘里面怎么数据迁移 浏览:591
电脑存放图片有什么文件夹 浏览:260
appleid不对怎么激活 浏览:574
省份表单代码 浏览:194
js原型继承运行机制 浏览:440
jstl判断的参数 浏览:86

友情链接