Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

JSP + XML

  • 27-04-2009 3:18pm
    #1
    Registered Users, Registered Users 2 Posts: 269 ✭✭


    I have a jsp calling a string variable called result inside result i have and xml syntax how do i format (parse) the xml in the string variable

    the xml elements are not showing in the jsp page however here is what is stored in vairiable

    <?xml version="1.0"?><Travel 2.0><TripID>23</TripID><Description>Describe trip!!</Description><DateFrom>04-05-09</DateFrom><DateTo>06-05-09</DateTo><Reason>Reason for trip!!</Reason><Dept>Computing</Dept><EmpNum>20016523</EmpNum></Travel 2.0>

    jsp
    
    
    
    <%@ page errorPage="errorpage.jsp" language="java" import="java.util.*,ie.travel.webservice.clients.*,ie.travel.servlets.*,travel.travelbeans.*" pageEncoding="UTF-8"%><html>
    	
    
    <head>
     <%
    	HttpSession mySession = request.getSession(true);
        TripBean triphistory = (TripBean)mySession.getAttribute("TripHistory");
    %>
      <jsp:useBean id="TripHistory" class="travel.travelbeans.TripBean" scope="session" >
     
      </jsp:useBean>  
     
      <jsp:setProperty name="TripHistory" property="*" /> 
       
      <%mySession.setAttribute("TripHistory",triphistory);%>
    	<title>Travel 2.0: Trip</title>
    	<link rel="stylesheet" href="../style.css" type="text/css"/>
    </head>
    
    <body>
    	<div id="wrapper">
    		<div id="header">
    			<h1><img src="../images/TravelBanner.gif"></h1>	
    		</div>
    		<div id="headline">
    			</div>
    	
    		<div id="body">
    			<div id="body-left">
    				<div class="green" >
      <div id="slatenav" style="center: 900px; width: 700px; top: 10px">
    	<ul>
    	<li><a href="index.html" title="Homepage">Homepage</a></li>
    	<li><a href="trip.html" title="Trip">Trip</a></li>
    	<li><a href="subsistence.html" title="Subsistence">Subsistence</a></li>
    	<li><a href="administration.html" title="Administration">Administration</a></li>
    	<li><a href="utilities.html" title="Utilities">Utilities</a></li>
        <li><a href="about.html" title="about">About</a></li>
    	</ul>
      </div>
    </div>
    <p>			
    	</div>
    	<div id="body-right3">
    	<center>
    	<p>
    	<p>
              <div id="stylized" class="myform" >
              <%
                TripClient tripclient = new TripClient();
                String Result = tripclient.getTripRecord(TripHistory);
              %>
    
    <h1>Web Service Entry Confirmation</h1>
    <p> Employee <b>${TripHistory.tripid}</b></p>
    
    <center><b><%=Result%><b></center>
    </div>
    <div class="spacer"></div>
    
    </div>
        </center>
    </div>
    <div id="body-right2">
    		<div class="arrowgreen" align="left">
    	<ul>
    		<li><a href="createtrip.jsp" title="Create Trip">Create Trip</a></li>
    		<li><a href="triphistory.jsp" title="Trip History">Trip History</a></li>
    		<li><a href="removetrip.jsp" title="Remove Trip">Remove Trip</a></li>
    	</ul>
    </div>
    </div>
    </body>
    </html>
    


Comments

  • Moderators, Science, Health & Environment Moderators Posts: 10,088 Mod ✭✭✭✭marco_polo


    This will escape the xml tags so the browser does not try to display them
    <%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
    
     ......
    <c:out value="${Result}" />
    

    The output will not be pretty, just whatever is in the string, but I gather what you want is just to display the raw xml?


  • Registered Users, Registered Users 2 Posts: 269 ✭✭cyberwit


    I want to format the result so the results look good to the screen one i use the code u suggested can i then use css


  • Registered Users, Registered Users 2 Posts: 6,240 ✭✭✭hussey


    cyberwit wrote: »
    I want to format the result so the results look good to the screen one i use the code u suggested can i then use css

    yes, but you need to link it to the css
    http://www.w3schools.com/xml/xml_display.asp


  • Moderators, Science, Health & Environment Moderators Posts: 10,088 Mod ✭✭✭✭marco_polo


    I would have said no, you would have to use XSLT to format the XML. You learn something new everyday. :)

    But if the CSS method hussey suggests works ok then that will make it alot easier.

    If you cannot get the CSS method working this code sample shows how to use a basic XSLT Tramsformation in a JSP page (Basic XSLT has a small learning curve but it is not too complicated).

    http://www.java2s.com/Code/Java/JSP/JSPXMLandXSLTtransform.htm


Advertisement