0

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.

Brian Cheong
  • 61
  • 3
  • 12
  • how to get request parameter within JSP https://stackoverflow.com/questions/1890438/how-to-get-parameters-from-the-url-with-jsp – spiritwalker Sep 20 '17 at 01:15
  • A big hint here is to separate your display (JSP) from your java code (servlet). Another hint is to **never** simply swallow your exceptions - always print something. – Scary Wombat Sep 20 '17 at 02:15
  • Hi @ScaryWombat, thanks for the hints. Able to solve the problem by removing the jsp tag (<%= %>) – Brian Cheong Sep 20 '17 at 03:38

0 Answers0