我有一个带有下拉框和文本框的html页面。
在下拉列表中单击选项时,必须使用java或java脚本(无数据库)在文本框中填充.properties文件中的值。
我的属性文件:
servers=Demo
serversTolookfor=Links,name
Demo_name=Demo Server
Demo_Links=https://mobileapplication.gh:8080
server.html:
<table class="edit" cellpadding="15"><tr>
<td style="color: white;" >Server Name:</td>
<td align="right"><selectname="serverName" class="dropdown">
<option value="Demo Server">Demo Server</option>
</select></td></tr>
<tr><td align="left" style="color: white;" >Server Link:</td><td align="right"><input type="text" name="server"></td>
</tr>
</table>
<input type="Submit" value="Save">
&#13;
答案 0 :(得分:0)
在你的jsp(不要使用html文件)文件中使用占位符。
春季配置
<util:properties id="propertyConfigurer"
location="classpath:yourPropertyFileClasspathHere "/>
<context:property-placeholder properties-ref="propertyConfigurer" />
<强> JSP 强>
<spring:eval expression="@propertyConfigurer.getProperty('propertyNameHere')" />
答案 1 :(得分:0)
我希望你这样想:
config.properties内容
#Crunchify Properties
user=Crunchify
company1=Google
company2=eBay
company3=Yahoo
CrunchifyReadConfigMain.java
package crunchify.com.tutorial;
import java.io.IOException;
public class CrunchifyReadConfigMain {
public static void main(String[] args) throws IOException {
CrunchifyGetPropertyValues properties = new CrunchifyGetPropertyValues();
properties.getPropValues();
}
}
CrunchifyGetPropertyValues.java
package crunchify.com.tutorial;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Date;
import java.util.Properties;
public class CrunchifyGetPropertyValues {
public String getPropValues() throws IOException {
String result = "";
Properties prop = new Properties();
String propFileName = "config.properties";
InputStream inputStream = getClass().getClassLoader().getResourceAsStream(propFileName);
if (inputStream != null) {
prop.load(inputStream);
} else {
throw new FileNotFoundException("property file '" + propFileName + "' not found in the classpath");
}
Date time = new Date(System.currentTimeMillis());
// get the property value and print it out
String user = prop.getProperty("user");
String company1 = prop.getProperty("company1");
String company2 = prop.getProperty("company2");
String company3 = prop.getProperty("company3");
result = "Company List = " + company1 + ", " + company2 + ", " + company3;
System.out.println(result + "\nProgram Ran on " + time + " by user=" + user);
return result;
}
}
输出:
Company List = Google, eBay, Yahoo
Program Ran on Mon Feb 23 21:54:55 PDT 2015 by user=Crunchify
答案 2 :(得分:0)
如果你想在普通的jsp中使用以下代码:
<%@ page import="java.io.FileInputStream"%>
<%@ page import="java.util.Properties"%>
<%
Properties property = null;
FileInputStream fis = new FileInputStream("path of A.properties") ;
property =new Properties();
property.load(fis);
String username = property.getProperty("username");
%>