如何在jsp中使用属性文件 [英] how to use property file in jsp
本文介绍了如何在jsp中使用属性文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
如何将.properties文件加载到jsp中
我试图在JSP中使用我的属性文件,但它无法正常工作并抛出错误
I am trying to use my property file in JSP but it wont work properly and throws an error
Error: myproperties.properties (The system cannot find the file specified)
这里我试图访问我的属性文件:
Here I am trying to access my property file:
<%
try
{
FileInputStream fis = new FileInputStream("myproperties.properties");
Properties p = new Properties();
p.load(fis);
String LogFileName = p.getProperty("NameOfLogFile");
out.println(LogFileName);
}
catch (Exception e)
{// Catch exception if any
out.println(e.getMessage());
}
我尝试了很多方法来访问属性文件。我如何解决这个问题?
I have tried by many ways to access property file. How do I fix this?
推荐答案
在包中创建test.properties文件
create test.properties file in your package
pname=xyz
psurname=abc
创建jsp文件:
<%@ page language="java" import="java.util.*" %>
<%@ page import = "java.util.ResourceBundle" %>
<% ResourceBundle resource = ResourceBundle.getBundle("test");
String name=resource.getString("pname");
String surname=resource.getString("psurname"); %>
<%=name %>
<%=surname%>
这篇关于如何在jsp中使用属性文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文