开发者

XML Doc in JSP with sessionvariables

I have a JSP开发者_C百科 page where I am trying to display a Session Variable that is a string in XML format. I am attempting to do this by setting the contentType to text/xml but the solution to my problem seems to not be that simple. The String will show up as plain text. Here's the small code snipp:

    <%@ page language="java" contentType="text/xml; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<webiDocument>
<% Object xml = session.getAttribute("XMLstring");
    String XML = xml.toString();%>
<%= XML %>
</webiDocument>

of course only the tag is showing up as XML, I can't get the session variable to display the same way. I'm guessing I have to go a whole new route with this page. Any ideas?


if your problem is that the session variable is not displayed, even though it is set properly from the above code,, then try modifying the above code by directly getting the session variable as a String(by type casting) instead of creating a Object and then converting as given below,, works well for me,,

<%@ page language="java" contentType="text/xml; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<webiDocument>
<%     String XML = (String)session.getAttribute("XMLstring");
%>

<%= XML %>
</webiDocument>

Getting the following on client:

<webiDocument>null</webiDocument>

as the session variable is null for me,, if you have initialized properly then this might work

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜