0
我嘗試使用資源文件創建一個XML數據轉換成JSP:創建XML數據集中到JSP
MyData.properties:
nombreOfQuestions=2
question1.description=what is the color?
question1.responseValue1=Red
question1.responseValue2=yellow
question1.responseValue3=white
question2.description=what is the Weight?
question2.responseValue1=70
question2.responseValue2=75
question2.responseValue3=80
myJsp.jsp:
<?xml version="1.0" encoding="UTF-8"?>
<%@ page import="MessageResourcesHelper"%>
<%
MessageResourcesHelper helper = new MessageResourcesHelper (pageContext, "MyData");
String nombreOfQuestions= helper.getProperty ("nombreOfQuestions",0);
%>
<Question>
<description>what is the color?</description>
<response>
<value>Red</value>
<value>Yellow</value>
<value>White</value>
</response>
</Question>
<Question>
<description>what is the Weight?</description>
<response>
<value>70</value>
<value>75</value>
<value>80</value>
</response>
</Question>
有任何使用java從myData.properties動態修復「描述」和「值」的任何方式,無論我有什麼樣的問題?
感謝Dave的迴應。但問題是,我不知道如何迭代postreties文件加載後 –
@naj_ib哦。嗯。您是否考慮過查看[API文檔](http://docs.oracle.com/javase/6/docs/api/java/util/Properties.html)?這裏有一個[方法](http://docs.oracle.com/javase/6/docs/api/java/util/Properties.html#propertyNames()),看起來可能有所幫助。 –
它已完成,現在我的jsp已準備好由Jaxb轉換器進行加載:嘗試{} { synchronized(_unMarshaller){ jaxbElement =(JAXBElement >)_unMarshaller.unmarshal(inStream); }(inStream是我的jsp作爲InputStream),但我得到這個Jaxbexception:(JaxbHelper.java:115)意外元素(uri:「」,local:「script」)。預期的元素是<{}問卷> –