I have a .jsp which determines what specific things a user has access to. It creates an XML file which is read into a stream by the previous jsp. How would I populate a table with the XML data which is read into a char array stream?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There are a lot of ways to get a HTML table out of the XML file. One of the most clean ways is to parse that XML into a collection of reuseable javabeans which you pass to the JSP, so that you can use JSTL
<c:forEach>to iterate over it while rendering a HTML table. This way every layer keeps its own clear responsibility. The Java SE provided JAXB is very helpful in this.Imagine that your XML look like this:
Then you can create a JAXB javabean as follows:
Then you can transform it into a
List<Entry>as follows:Then you can let your servlet (or JSP? :/ ) store it in the request scope before forwarding the request to the JSP:
Finally you can in JSP iterate over it and present it as a HTML table: