I am trying to read a xml data from url with a parameter, eg. http://10.10.123.10/demo/hierarchy/abcdef=?ag_id=10, which the value of ag_id is based on the agency I have selected on my previous page.
The problem is, I do not how to let xml reader reads the url based on the ag_id.
I have the following codes now:
<body>
<% try { %>
<%
String strAgId = demoHandler.getParamValue(request, "AgId"); //value:10
String strUrl = demoHandler.getProperties("Agency"); //value:http://10.10.123.10/demo/hierarchy/
String strToken = demoHandler.getProperties("Token"); //value:abcdef=
%>
<table border="0" width="100%">
<tr>
<td class="title">Department</td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td>
<table border="0" width="100%" cellpadding="0" cellspacing="0">
<tr>
<td class="heads" width="5%">No.</td>
<td class="heads" width="85%">Agency</td>
<td class="heade" width="10%">Select</td>
</tr>
//Read XML data
<%
try {
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
Document doc = docBuilder.parse(new File(strUrl + strToken + "?ag_id=" + <%= strAgId %>));
%>
<% } catch (Exception e) { e.printStackTrace(); %>
<tr>
<td colspan="3" class="tablee">Fail to read xml data.</td>
</tr>
<% } %>
</table>
</td>
</tr>
</table>
<% } catch (Exception e) { %>
<% } finally { %>
<% } %>
</body>
I tried to add <%= strAgId %> at docBuilder.parse() but I was unable to compile with the error: illegal start of expression. Please give me some suggestion on this. Thanks in advance.