导航:首页 > 文件教程 > 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获取配置文件相关的资料

热点内容
数据库有哪些表格 浏览:741
bada12微信java 浏览:16
小白编程什么最好学 浏览:205
qq回头看头像 浏览:338
苹果换屏要多长时间 浏览:283
如何用平板电脑学编程 浏览:424
格式工厂怎么转换swf文件 浏览:817
怎么做一个试用网站 浏览:953
哪里有信息不对称的app 浏览:59
win10的gpeditmsc文件 浏览:451
4399游戏盒20版本 浏览:349
有什么找工作比较靠谱的app吗 浏览:921
如何给网站挂黑链 浏览:282
360断网急救箱网络异常修复不了 浏览:889
身份证验证的js文件 浏览:994
什么人经常换微信名字 浏览:707
网站源码挖掘 浏览:944
荔枝fm和app哪个播放量好 浏览:535
乐秀音频在哪个文件里 浏览:486
以数据说话什么意思 浏览:319

友情链接