jsp读取properties配置文件

<%@ page language="java" import="java.util.*,java.io.*" pageEncoding="utf-8"%>
<meta name="page-view-size" content="640*530">
<%
 String path = "";
  
 Properties pro = new Properties();  
 String realpath = request.getRealPath("/WEB-INF/classes");  
 try{  
	 //读取配置文件
	 FileInputStream in = new FileInputStream(realpath+"/config.properties");  
	 pro.load(in);  
 }  
 catch(FileNotFoundException e){  
     out.println(e);  
 }  
 catch(IOException e){
	 out.println(e);
 } 

 //通过key获取配置文件
 path = pro.getProperty("host"); 
 //byte b[]=title.getBytes("utf-8");
 //title=new String(b);
 
%>
<html>
	<head>
	<script type="text/javascript">
		var path = '<%=path%>';
		alert(path);
	</script>
	</head>
	<body>
	</body>
</html>

注:xxx.properties文件在src/main/resources下面时,相当于在服务器/WEB-INF/classes路径下——


猜你喜欢

转载自blog.csdn.net/KingJin_CSDN_/article/details/77964060