JSP & XML
I am trying to create an XML file via a JSP. I want to be able to take the user input and store it in an XML whihc can be appeneded. The problem is that I can take the user input and create the XML file but if the user tries again this happens:
<?xml version="1.0"?>
<users>
<user>
<username>bob</username>
<password>bob</password>
</user>
</users>
<?xml version="1.0"?>
<users>
<user>
<username>mjs</username>
<password>mjs</password>
</user>
</users>
Below is the section of code which I have been using:
<file:writeFile source="/WINDOWS/Desktop/JSPs/Xslt/redneck/users.xml" append="true"><?xml version="1.0"?>
<users><% if(user != null){
%>
<user>
<username><%=user%></username>
<password><%=pass1%></password>
</user>
<%}%></users>
</file:writeFile>
PLEASE somebody show me the light!!!
So your problem is that the new data gets appended to the old data? In that case, although I know nothing about the tag you are using, I would hazard a guess that this attribute is the problem:
append="true"
Similar Messages
-
HELP: JSP + XML + XSLT = HTML?
Hello, all.
I am trying out Weblogic 6 and I am trying to get the JSP + XML + XSLT =>
HTML chain working.
I am coming from using Orion and SAXON.. and in that situation I had a JSP
that contained XML tags... they were filled in at runtime and then using
Servlet-Chaining was passed along to the SAXON XSLT Processer. SAXON checked
for the inline XSL specified and then used that to transform the document
into HTML.
It worked well, but there were some other features missing/not documented
that we now need.
With Weblogic I am trying to use the XSLT Tag Library that comes with the
distribution, but it seems to be very finicky. I followed the directions and
I got it to do a sort of roundabout transformation. But it doesn't seem to
work quite right.
The best I can get is the following:
I have an 'xslt' directory url-pattern-mapped to xslt.jsp (as instructed)...
but can't figure out how to specify the xsl file on-the-fly... that is, if I
don't hard-code the XSL file in the x:xslt element in the xslt.jsp it
complains about some XML file not having a root element.
Ideal situation:
1. I have a JSP that includes XML elements.
2. It is filled from a database at runtime and specifys (using a PI) what
XSL stylesheet it is to be processed with.
3. Somehow (fingers crossed) the XML is processed and transformed into HTML
by the appropriate XSL file.
I think I am mostly stuck moving between steps 2 and 3.
Can anyone give me some hints? Are there some Weblogic specific
elements/tags that I have to include in the XML file that Weblogic will
catch and re-direct to the XSL Parser?
Please, anyone, if you have some information, I would much appreciate it.
Dylan Parker
PS - I apologize for the cross-post, I hope it doesn't cause too much
traffic.Craig,
I've since discovered how to do it with the WL Taglibrary... and have
moved on =)
It has to do with the EXTREMELY BADLY documented x:xml tag that can
appear within the x:xslt tag body...
So the WL Tag Library allows something like the following.
(Please note, angled brackets are omitted in this post to prevent html
parsing)
[x:xslt stylesheet="sheet.xsl"]
[x:xml]
Here is the XML to run the sheet on.
This should have all relevant XML syntax: the PIs, the doctype,
root elements etc...
[x:xml]
[x:xslt]
And that DOES work. But not very well. WL, a little prematurely
incorporated versions 1.2 of Xerces and Xalan in their product -- and
these versions have some irritating bugs.
Also -- There tag library doesn't copy the source XML across as UTF-8
.. so a lot of the Japanese I have embedded there (from a DB) gets
mangled somewhere in their code...
AND -- If you hammer a little bit on an JSP/XML that uses the WL Tag
Library (eg clicking refresh lots of times in IE)... I get huge
amounts of irritating exceptions appearing in the log files.
NullPointerExceptions
XSL Parsing Exceptions
XML Parsing Exceptions
but completely unpredictably...
In my eyes.. the WL XML/XSL Tag Library using the incorporated and
untouchable Xalan and Xerces (v1.2) is virtually unusable.
What a pain.
BUT! Apache offers a similar OPEN SOURCE XSL Tag Library available
here:
http://jakarta.apache.org/taglibs/doc/xsl-doc/intro.html
And it uses the standard, non-weblogic-incorporated, Xerces and Xalan
(which means you can provide whatever version you want).. and it works
impressively well.
It has almost identical performance as the WL Taglib, and without all
of the bizarre exceptions being thrown.
And it does proper passing of the character encoding type!
If only the taglib did caching though =(
The performance hit over pure JSP is huge. Almost two orders of
magnitude. On my desktop box I can get around 500Requests/Sec if I am
returning HTML direct from a JSP... while if I produce XML that gets
processed by XSL into HTML the Requests/Sec drops to 5!!!!
Caching. Caching. And more Caching. A lot of DiskIO is going on with
the XML/XSL/XHTML chain of events.
I hope this helps!
I'd be curious as to what you find out as well.
Dylan Parker
On 5 Mar 2001 07:20:00 -0800, "Craig Macha"
<[email protected]> wrote:
>
Yep, I feel Dylan's pain.
I am trying to accomplish the same thing. A JSP page generating
dynamic XML content and then utilizing an XSLT stylesheet to transform
all the content into XHTML.
Does anyone have some examples that show exactly how to accomplish
this? Can I do this with WLS and the XML taglib that comes with
it? Or do I have to move on to something like Cocoon to get this
capability?
Any insight would be greatly appreciated.
Thanks,
Craig Macha
"Dylan Parker" <[email protected]> wrote:
Hello, all.
I am trying out Weblogic 6 and I am trying to get the
JSP + XML + XSLT =>
HTML chain working.
I am coming from using Orion and SAXON.. and in that situation
I had a JSP
that contained XML tags... they were filled in at runtime
and then using
Servlet-Chaining was passed along to the SAXON XSLT Processer.
SAXON checked
for the inline XSL specified and then used that to transform
the document
into HTML.
It worked well, but there were some other features missing/not
documented
that we now need.
With Weblogic I am trying to use the XSLT Tag Library
that comes with the
distribution, but it seems to be very finicky. I followed
the directions and
I got it to do a sort of roundabout transformation. But
it doesn't seem to
work quite right.
The best I can get is the following:
I have an 'xslt' directory url-pattern-mapped to xslt.jsp
(as instructed)...
but can't figure out how to specify the xsl file on-the-fly...
that is, if I
don't hard-code the XSL file in the x:xslt element in
the xslt.jsp it
complains about some XML file not having a root element.
Ideal situation:
1. I have a JSP that includes XML elements.
2. It is filled from a database at runtime and specifys
(using a PI) what
XSL stylesheet it is to be processed with.
3. Somehow (fingers crossed) the XML is processed and
transformed into HTML
by the appropriate XSL file.
I think I am mostly stuck moving between steps 2 and 3.
Can anyone give me some hints? Are there some Weblogic
specific
elements/tags that I have to include in the XML file that
Weblogic will
catch and re-direct to the XSL Parser?
Please, anyone, if you have some information, I would
much appreciate it.
Dylan Parker
PS - I apologize for the cross-post, I hope it doesn't
cause too much
traffic. -
JSP, XML, XSLT: applying XSL on JSP-generated XML doc
Hello,
I am currently trying to figure out how to do the following:
let's consider (that's not entirely hypothetical :) ) a web application working with JSP (on apache/tomcat 3.1) and oracle BC4J Application modules.
The JSPs call oracle webbeans to perform updates and retrieve data from an 8.1.6 database.
Now I'm thinking of moving to a combination of JSP, XML and XSL, which (hopefully) would allow to customize the application depending on the user's browser, language etc...(that's the point isn't it?)
It doesn't seem to be a problem to produce XML from a jsp, send it directly to the client browser, which in turn goes to look for the proper XSL file and does all the transformation stuff.
However this only works with I.E 5 for the moment right? and most website need to support various kinds of browsers...
The need is:
* When a non XML-capable browser is detected, apply the proper XSL(s) on the server side before sending the result back, in html/wml/whatever...
* For XML-capable browsers, produce raw XML, maybe apply some XSL(s), and eventually send the result to the browser which handles the rest of the XSL stuff itself.
Therefore, I'd like to:
- Have the jsp produce the raw xml data (maybe adding extra tags, to indicate the browser and/or the language that the jsp engine has detected).
- Pass the output to a first XSLT engine which would take care of the language stuff
- Feed the result into a second XSLT engine to handle browser specificities for instance...
- Send the final output to the client browser.
Now, there are 2 problems:
* 1/ I have seen various engines capable of chaining XSL transforms, and it is easy to produce XML from a jsp, but I don't know how to feed a jsp's output into an XML engine. is that possible? how?
* 2/ I'm a bit concerned about the cost of applying three (or more) process stages, does anyone have insight on the performance issues this could raise?
bonus question ;) : is there a simpler approach?
Thanks a lot in advance, Remi
nullHello,
I am currently trying to figure out how to do the following:
let's consider (that's not entirely hypothetical :) ) a web application working with JSP (on apache/tomcat 3.1) and oracle BC4J Application modules.
The JSPs call oracle webbeans to perform updates and retrieve data from an 8.1.6 database.
Now I'm thinking of moving to a combination of JSP, XML and XSL, which (hopefully) would allow to customize the application depending on the user's browser, language etc...(that's the point isn't it?)
It doesn't seem to be a problem to produce XML from a jsp, send it directly to the client browser, which in turn goes to look for the proper XSL file and does all the transformation stuff.
However this only works with I.E 5 for the moment right? and most website need to support various kinds of browsers...
The need is:
* When a non XML-capable browser is detected, apply the proper XSL(s) on the server side before sending the result back, in html/wml/whatever...
* For XML-capable browsers, produce raw XML, maybe apply some XSL(s), and eventually send the result to the browser which handles the rest of the XSL stuff itself.
Therefore, I'd like to:
- Have the jsp produce the raw xml data (maybe adding extra tags, to indicate the browser and/or the language that the jsp engine has detected).
- Pass the output to a first XSLT engine which would take care of the language stuff
- Feed the result into a second XSLT engine to handle browser specificities for instance...
- Send the final output to the client browser.
Now, there are 2 problems:
* 1/ I have seen various engines capable of chaining XSL transforms, and it is easy to produce XML from a jsp, but I don't know how to feed a jsp's output into an XML engine. is that possible? how?
* 2/ I'm a bit concerned about the cost of applying three (or more) process stages, does anyone have insight on the performance issues this could raise?
bonus question ;) : is there a simpler approach?
Thanks a lot in advance, Remi
null -
What changes i should made in web.xml for using jsp/xml using weblogic
Hi all,
I just know some changes has to made in web.xml or weblogic.xml if i have to use weblogic for jsp/xml.
Pls. anybody post the steps to intereaction with xml using weblogic.
I am using jdk1.4The problem is solved.
The information is given at
http://e-docs.bea.com/wls/docs61/webapp/webappdeployment.html -
JSP xml syntax, taglibs not found
Hello,
I have JSPs look so:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE jsp:root [
<!ENTITY nbsp " ">
]>
<jsp:root version="1.2"
xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:afc="http://afclabs.com/tags/afc"
xmlns:c="http://java.sun.com/jstl/core">
<jsp:directive.page language="java" contentType="text/html; charset=iso-8859-1"/>
<afc:page>
<head>
<title></title>
</head>
<body>
</body>
</afc:page>
</jsp:root>[/code:1:449443877c]
If I use Tag Libraries panel, to insert , for example <c:out> tag, then the tag will be inserted along with this line: <%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>, like so:
[code:1:449443877c]<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE jsp:root [
<!ENTITY nbsp " ">
]>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<jsp:root version="1.2"
xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:afc="http://afclabs.com/tags/afc"
xmlns:c="http://java.sun.com/jstl/core">
<jsp:directive.page language="java" contentType="text/html; charset=iso-8859-1"/>
<afc:page>
<head>
<title></title>
</head>
<body>
<c:out value="test" default="test"/>
</body>
</afc:page>
</jsp:root>[/code:1:449443877c]
I don't need this line, because the tag libraries are defined in the <jsp:root> tag.
How can I stop the automatically insert of this line ?
How to make, that the Nitrox "undestand" this tag:
[code:1:449443877c] <jsp:root version="1.2"
xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:afc="http://itoolabs.com/tags/afc"
xmlns:c="http://java.sun.com/jstl/core">[/code:1:449443877c] ?
Thankshttp://java.sun.com/products/jsp/docs.html
To my knowledge, only Tomcat 5 will use the 2.0 specs. Other servers will use the 1.2 spec, but the server docs should state which JSP spec they support.
I found the 'Card' PDF the most helpfull. The 'Reference' is quick and easy, but you don't get as much info as quickly, IMO (for example I couldn't find the information to help here in the 'Reference' but it was right on top in the 'Card') -
I'm trying to write a jsp page that goes to the following page and returns the XML it generates, parses it, then prints out to the screen what it is.
maybe I'm over thinking this but it's driving me nuts
thanks in advance
Pete
here's my code
<%@ page import = "java.io.*, java.util.*, java.lang.*" %>
<%@ page import = "oracle.portal.provider.v2.render.PortletRenderRequest" %>
<%@ page import = "oracle.portal.provider.v2.http.HttpCommonConstants" %>
<%@ page import = "oracle.portal.provider.v2.url.*" %>
<%@ page import = "org.campuseai.ErrorHandler" %>
<%@ page import = "java.net.*" %>
<%@ page import = "java.lang.String" %>
<%
response.setHeader("Cache-Control", "no-cache");
response.setHeader("Pragma", "no-cache");
response.setHeader("Content-type", "text/html");
response.setHeader("Expires", "Thu, 29 Oct 2000 17:04:19 GMT");
PortletRenderRequest pr = (PortletRenderRequest) request.getAttribute(HttpCommonConstants.PORTLET_RENDER_REQUEST);
String hslURL = UrlUtils.absoluteLink(pr, "/");
%>
<%
String level5 = (hslURL + "severe.png");
String level4 = (hslURL + "high.png");
String level3 = (hslURL + "elevated.png");
String level2 = (hslURL + "guarded.png");
String level1 = (hslURL + "low.png");
String hlsURL = "http://www.dhs.gov/dhspublic/getAdvisoryCondition";
String inputLine;
String hlsTest5 = "SEVER";
String hlsTest4 = "HIGH";
String hlsTest3 = "ELEVATED";
String hlsTest2 = "GUARDED";
String hlsTest1 = "LOW";
URL gov = new URL(hlsURL);
try {
gov.openConnection();
catch (MalformedURLException e) {
System.out.println(e.getMessage());
BufferedReader in = new BufferedReader(new InputStreamReader(gov.openStream()));
while ((inputLine =in.readLine()) != null) {
out.println(inputLine);
if (inputLine.equals(hlsTest5))
out.println("SEVER");
if (inputLine.equals(hlsTest4))
out.println("HIGH");
if (inputLine.equals(hlsTest3))
out.println("ELEVATED");
if (inputLine.equals(hlsTest2))
out.println("GUARDED");
if (inputLine.equals(hlsTest1))
out.println("LOW");
in.close();
%>I did is 9 lines of code in php youo 'd think it would be easy to convert!
Pete
just in case anybody wanted the php code:
<?php
$saURL = "http://www.dhs.gov/dhspublic/getAdvisoryCondition";
$myFile= (file($saURL));
$text = str_replace("<THREAT_ADVISORY CONDITION=\"","",$myFile[1]);
$myFile = str_replace("\" />","",$text);
$myFile = trim($myFile).".png";
$myFile = strtolower($myFile);
echo "<center><a href=\"http://www.dhs.gov/\" target=\"blank\"><img src=\"level/" . $myFile . "\" vspace=5 border=0></a></center>";
?> -
Can anybody please help me with a small programme of how to use xml to store data retrieved from database and then display it on a jsp page.
There is a good tutorial on developer works.
Follow the url:
http://www.javaworld.com/javaworld/jw-01-2000/jw-01-dbxml_p.html
Hope this helps. -
Hello.
I have a device that produce XML output file( dynamically )
I need to read it by Jsp page.
I able to do it using XSL but when XML changes my Jsp page is not updated.
Only if i recompile jsp page i get new data
Do you know some methods to get dynamically XLM data?
Thx
Riccardo
example code:
<%@page contentType="text/html"%>
<html><head><title>XSLT Example</title>
<%@ taglib uri='/WEB-INF/tlds/xslt.tld' prefix='xslt' %>
</head>
<body>
<xslt:apply xsl='Fieldgate.xsl'>
<%@ include file='output.xml' %>
</xslt:apply>
</body></html>Thats because you are including your XML in your JSP.
If you were to parse your XML in your in your JSP using SAX or DOM and then use them to populate the dynamic contents of your JSP then you will not need to recomplie your JSP.
Read the following article. It will help you out and possibly give you some other Ideas.
http://developer.java.sun.com/developer/technicalArticles/xml/WebAppDev2/#code13 -
I hava a JSP application that uses the XDK to query the database and display XML rowset data to a JSP. This rowset data can be a few hundred rows or up to 50,000 rows,
as we publish technical manuals, parts manuals and wiring manuals for aircraft.
Getting the data to display within the JSP is not a problem. The problem is
that the XML rowset data shares two purposes:
1. Query by Example, returning
XML formatted data for display within a browser.
2. Use of the XML formatted
data as an external entity file for our SGML authoring software to print the
paper publication.
The JSP I developed (I'm not sure I should take credit for it) uses the XMLData bean and it will open the browser File/SaveAs dialog in both Netscape (Unix) and IE5.5 (Windows). HOWEVER, when I create a second JSP to perform the same task on a different table the JSP errorpage shows with no error and no errors within the JDeveloper console. This has been kicking my butt for some time, and would very much appreciate a workable solution. I will share whatever I can share with the provider. Here is the JSP code.
=============================================
<?xml version="1.0"?>
<%@ page language = "java" errorPage="errorpage.jsp" import = "java.io.*, java.util.*, oracle.jbo.*, javax.naming.*, oracle.jdeveloper.html.*, oracle.jbo.html.databeans.*" contentType="text/html;charset=ISO-8859-1" %>
<jsp:useBean class="oracle.jbo.html.databeans.XmlData" id="h25EqXml" scope="request" >
<%
h25EqXml.setResultElement("equiptbl");
h25EqXml.setReleaseApplicationResources(true);
h25EqXml.setDisplayAttributes("Ein,Pnr,Nomen,Cage,Diagnbr,Sht,Effect");
h25EqXml.initialize(pageContext,"h25Wires_JspApp_h25Wires_be_H25Wires_beModule.HU25A_Equipment");
response.setContentType("text/sgml");
response.setHeader("Content-location","attachment;filename="+"equiptbl.sgm");
ServletOutputStream sos = response.getOutputStream();
BufferedInputStream bis = new BufferedInputStream (new FileInputStream("equiptbl.sgm"));
int data;
while((data = bis.read()) != -1)
sos.write(data);
bis.close();
sos.flush();
sos.close();
%>
<jsp:forward page= "HU5A_Equipment_Browse.jsp" />
</jsp:useBean>
============================================
The code for the other pages is the same with the exception of the filename xxx.sgm and the bean id.
I very much appreciate your help. Thanks!
nullHello Paulo,
thank you for your answer, but i'm using type 04 XML for SEPA.
when i select Type XML, the fields "output to file system" and "filename" are hidden.
i dont understand why ... -
How is the best way to complete this task. I hava a servlet which accesses a database and retreives a list of employees. then sends it to jsp. I would like to be able to viewthat list, via jsp, in xml or regular html. How should the servlet send the employee list to the jsp page? Should the servlet always send out as xml and the jsp page can transforms the xml to html. This way I dont have to convert to xml when I want to view it as xml. Or should the servlet send out as vector to two pages. The first page transforms it into html. The second page transforms it into xml. What are the pros/cons of either option.
thanksThats what I initially concluded until I thought about
it some more. What if we consider that sending out
the data as xml is not for display purpouses, just an
alternative to vectors, another way to send out data.
It just happens to be the same as a display type in
JSP.
servlet | display type
xml -> xml
xml -> HTML
xml -> WML
How do Enterprise Java Beans work? Does EJB send
data out as XML to front-end web server's servlets(I
dont know anything about EJB)? Like so:
rdbms -> ejb(xml) -> tomcat servlet(xml) -> jsp
thanksYeah, I don't know anything about EJBs. I know that XML is used as a transport mechanism, but often it is used to transport accross applications. It is universal, so if the applications are in different languages, they can still communicate. Or if you are running on different JVMs, you can't pass a vector between them, but if you put it into XML, you can still communicate.
Anyways, it still takes work, both time and effort, to build the XML. Then you have to read it and tranlate it back so you can put it into HTML. It just seems like putting it into a collection is more efficient when you are not crossing applications or JVMs. -
Hi !
i am creating a program using JSP Ajax that read PUBLIC enteries of Google calender but when i run to check the JSP file [that is Server Side process & return result to HTML] i got the following result:
375/-+1750/-Bunty [email protected]://www.google.com/calendar/feeds/bunty.india%40gmail.com/public-031eeb071629562bb65d8d446f5f2b59/basic/n21nl92hsg9mljbv0ntsrlrhp42006-11-14T10:12:59.000Z2006-11-14T10:13:22.000ZWhen: 2006-11-14 <br> <br>Event Status: confirmedWhen: 2006-11-14 <br> <br>Event Status: confirmedBunty [email protected]://www.google.com/calendar/feeds/bunty.india%40gmail.com/public-031eeb071629562bb65d8d446f5f2b59/basic/o7ttfhhs2fbsjl34m08026h2102006-11-14T10:11:31.000Z2006-11-14T10:12:05.000ZWhen: 2006-11-17 13:00 to 14:00 IST <br> <br>Event Status: confirmedWhen: 2006-11-17 13:00 to 14:00 IST <br> <br>Event Status: confirmedBunty [email protected]://www.google.com/calendar/feeds/bunty.india%40gmail.com/public-031eeb071629562bb65d8d446f5f2b59/basic/kir9gd7c9gkf6va0283oicbivc2006-10-04T14:00:37.000Z2006-10-04T14:00:37.000ZWhen: 2006-10-15 17:00 to 18:30 IST <br> <br>Event Status: confirmedWhen: 2006-10-15 17:00 to 18:30 IST <br> <br>Event Status: confirmedBunty [email protected]://www.google.com/calendar/feeds/bunty.india%40gmail.com/public-031eeb071629562bb65d8d446f5f2b59/basic/6d628dcmei9f3kd2c705i282o02006-09-28T09:08:26.000Z2006-10-04T13:59:43.000ZWhen: 2006-10-07 10:00 to 11:00 IST <br> <br>Event Status: confirmedWhen: 2006-10-07 10:00 to 11:00 IST <br> <br>Event Status: confirmedBunty [email protected]://www.google.com/calendar/feeds/bunty.india%40gmail.com/public-031eeb071629562bb65d8d446f5f2b59/basic/i4o0s31ia8cuau5gn3l6ecvd582006-09-19T11:04:10.000Z2006-09-25T10:16:06.000ZWhen: 2006-10-15 15:00 to 16:00 IST <br> <br>Where: Rajouri Garden <br>Event Status: confirmedWhen: 2006-10-15 15:00 to 16:00 IST <br> <br>Where: Rajouri Garden <br>Event Status: confirmedBunty [email protected]://www.google.com/calendar/feeds/bunty.india%40gmail.com/public-031eeb071629562bb65d8d446f5f2b59/basic/vfu1bbrickckleptoh46m3v09k2006-09-25T10:15:19.000Z2006-09-25T10:15:19.000ZRecurring Event<br> First start: 2006-09-27 IST <br> Duration: 86400 <br>Event Status: confirmedRecurring Event<br> First start: 2006-09-27 IST <br> Duration: 86400 <br>Event Status: confirmedBunty
IE Error while executing
XML document must have a top level element. Error processing resource
But it should be a proper XML file.....
HTML Code:
function RSSRequest() {
// change the status to requesting data
HideShow('status');
document.getElementById("status").innerHTML = "Requesting data ...";
// Prepare the request
RSSRequestObject.open("GET", rssReader.jsp, true);
// Set the onreadystatechange function
RSSRequestObject.onreadystatechange = ReqChange;
// Send
RSSRequestObject.send(null);
<body onload="RSSRequest();">
<h2>Google Calendar Events - RSS Reader- BuntyIndia</h2>
<div id="status" style="display:none"></div>
<div id="ajaxreader"></div>
JSP Code:
<%@ page import = "java.io.*, java.util.*,java.net.URL,java.net.*,java.awt.*" %>
<%
response.setContentType("text/xml");
response.setHeader("Cache-Control", "no-cache");
response.setHeader("pragma","no-cache");
URL url = new URL(" http://www.google.com/calendar/feeds/bunty.india%40gmail.com/public-031e071629562bb68d446f5f2b59/basic");
URLConnection urlConnection = url.openConnection ( ) ;
StringBuffer stringbuffer = new StringBuffer("");
String news =new String();
try {
BufferedReader in = new BufferedReader ( new InputStreamReader (url.openStream())) ;
while((in.readLine())!= null)
//s2=in.readLine();
stringbuffer.append(in.readLine());
in.close();
catch(Exception e) {
System.out.println(e.getMessage());
//news=stringbuffer.toString();
//out.println(news);
response.getWriter().write(in);
%>Please Help
Bunty Indiayou don't want a scriptlet, you want an expression
<input type="TEXT" name="Product" value="<%= Product %>"> -
JSP XML file parsing XSLT using Xalan
Hi all
I have created an XML file "view_campaign.xml" using JSP as shown in a code below and i wanna know how i should proceed to parse the XML file and so i can display this XML as the XSLT file i created.
<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>
<%
// Identify a carriage return character for each output line
int iLf = 10;
char cLf = (char)iLf;
// Create a new empty binary file, which will content XML output
File outputFile = new File("C:\\WebContent\\view_campaigns.xml");
//outputFile.createNewFile();
FileWriter outfile = new FileWriter(outputFile);
// the header for XML file
outfile.write("<?xml version='1.0' encoding='ISO-8859-1'?>"+cLf);
try {
// Define connection string and make a connection to database
//DriverManager.registerDriver (new org.apache.derby.jdbc.ClientDriver());
Connection conn = DriverManager.getConnection("jdbc:derby://localhost:1527/sample","app","app");
Statement stat = conn.createStatement();
// Create a recordset
ResultSet rset = stat.executeQuery("Select * From campagn");
// Expecting at least one record
if( !rset.next() ) {
throw new IllegalArgumentException("No data found for the campaigns table");
outfile.write("<campaigns>"+cLf);
outfile.write("<campaign>"+cLf);
outfile.write("<campaign_id>" + rset.getString("campagn_id") +"</campaign_id>"+cLf);
outfile.write("<campaign_name>" + rset.getString("campagn_name") +"</campaign_name>"+cLf);
outfile.write("<campaign_type>" + rset.getString("campagn_type") +"</campaign_type>"+cLf);
outfile.write("<client>" + rset.getString("client_name") +"</client>"+cLf);
outfile.write("<positions>" + rset.getString("positions_nbr") +"</positions>"+cLf);
outfile.write("<begin>" + rset.getString("campagn_beginning_date") +"</begin>"+cLf);
outfile.write("<close>" + rset.getString("campagn_ending_date") +"</close>"+cLf);
outfile.write("</campaign>"+cLf);
// Parse our recordset
// Parse our recordset
while(rset.next()) {
outfile.write("<campaign>"+cLf);
outfile.write("<campaign_id>" + rset.getString("campagn_id") +"</campaign_id>"+cLf);
outfile.write("<campaign_name>" + rset.getString("campagn_name") +"</campaign_name>"+cLf);
outfile.write("<campaign_type>" + rset.getString("campagn_type") +"</campaign_type>"+cLf);
outfile.write("<client>" + rset.getString("client_name") +"</client>"+cLf);
outfile.write("<positions>" + rset.getString("positions_nbr") +"</positions>"+cLf);
outfile.write("<begin>" + rset.getString("campagn_beginning_date") +"</begin>"+cLf);
outfile.write("<close>" + rset.getString("campagn_ending_date") +"</close>"+cLf);
outfile.write("</campaign>"+cLf);
outfile.write("</campaigns>"+cLf);
// Everything must be closed
rset.close();
stat.close();
conn.close();
outfile.close();
catch( Exception er ) {
%>////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
this is my .XSL file
<?xml version="1.0" encoding="iso-8859-1" ?>
- <!-- DWXMLSource="view_campaigns.xml"
-->
<!DOCTYPE xsl:stylesheet (View Source for full doctype...)>
- <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="iso-8859-1" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" />
- <xsl:template match="/">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Gestion des campagnes</title>
</head>
- <body>
Gestion des campagnes
- <table border="1">
- <tr bgcolor="#9acd32">
<th align="left">Code</th>
<th align="left">Nom</th>
<th align="left">Type</th>
<th align="left">Client</th>
<th align="left">Nombre de positions</th>
<th align="left">Date d'ouverture</th>
<th align="left">Date de cl�ture</th>
</tr>
- <xsl:for-each select="campaigns/campaign">
- <tr>
- <td>
<xsl:value-of select="campaign_id" />
</td>
- <td>
<xsl:value-of select="campaign_name" />
</td>
- <td>
<xsl:value-of select="campaign_type" />
</td>
- <td>
<xsl:value-of select="client" />
</td>
- <td>
<xsl:value-of select="positions" />
</td>
- <td>
<xsl:value-of select="begin" />
</td>
- <td>
<xsl:value-of select="close" />
</td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>I would be greatful that u answer my question what i should do have any exemple case study.Hi,
Try this code
JspWriter out = pageContext.getOut(); // Get JSP output writter
javax.xml.transform.TransformerFactory tFactory = javax.xml.transform.TransformerFactory.newInstance(); //Instantiate a TransformerFactory.
String realPath = "c:/applyXsl.xsl";
java.io.File file = new java.io.File(realPath); // crearte a file object for given XSL.
// Use the TransformerFactory to process the stylesheet Source and generate a Transformer.
javax.xml.transform.Transformer transformer = tFactory.newTransformer(new javax.xml.transform.stream.StreamSource(file));
java.io.StringReader inputStream = new java.io.StringReader("c:/xmlFile.xml"); // create an input stream for given XML doc
java.io.ByteArrayOutputStream obj = new java.io.ByteArrayOutputStream(); // Create an output stream for XSL applied XML doc.
// 3. Use the Transformer to transform an XML Source and send the output to a Result object.
transformer.transform(new javax.xml.transform.stream.StreamSource(inputStream), new javax.xml.transform.stream.StreamResult(obj));
String outputString = obj.toString(); // get the XSL applied applied XML document for print
out.println(outputString); // print the XSL applied XML in to JSP.
however you need xercesImpl.jar and xml-apis.jar files to run this program.
Regards,
Ananth.P -
I am thinking of using xslt to generate html in jsps.
Can somebody point me to some good examples on how to architecture such a server side system. On best practices and so...
Thanks
-Shere is an example that you can use
I did put all of it in a bean, this is just for testing xsl
<%@ page
import="javax.xml.parsers.*,
org.w3c.dom.*,
javax.xml.transform.*,
javax.xml.transform.stream.*,
java.io.*"%>
<%
StreamSource xml = new StreamSource(new File("c:/xml/file.xml"));
StreamSource xsl = new StreamSource(new File("c:/xml/file.xsl"));
StreamResult result = new StreamResult(out);
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer(xsl);
transformer.transform(xml, result);
%> -
Web Based Messageboard (JSP, XML, XSLT) - Just Looking For Advice Please!
I have a general question - I am not looking for any code, just some advice if possible. I am studying on a Masters course and I have been given an assignment to do which I am having difficult getting started. I have worked a lot with Java up until now, however this is the first time I have had to JSP on my course.
My current assignment is that I am required to create a simple web based message board, using JSP and XML, which allows users to post messages to the board, and also to reply to messages. The content of the message board is stored in an XML file, and there is no database involved. The message data needs to be formatted for viewing in a browser using XSL transformations.
I am stuck as to how to go about starting the project, and this is all I am asking for advice in. I have created the basic XML file which has some preliminary data stored within it, and I have created an XSL stylesheet to transform this data, however I am stuck with the JSP. Do I need to create a seperate JSP page for each page of the website? How does this link in with the XSLT?
I would welcome and really appreciate any advice, but I stress that I am not looking for anyone to give me any code or anything like that.
Thanks.You can use XSLT to convert XML to HTML. Then include this HTML in your JSP. Further on you've a plain HTML form with an input field for a message which you submit to a servlet. In the servlet validate/convert/whatever this message and add it to the XML file and then forward/redirect the request back to the JSP.
-
I keep getting this error when I try to transform an xml file into html.
org.apache.jasper.JasperException: Unable to open taglibrary http://jakarta.apache.org/taglibs/xsl-1.0 : null
Here is the jsp file
<%@taglib uri="http://jakarta.apache.org/taglibs/xsl-1.0"
prefix="xsltlib" %>
<html>
<head>
<title>Book Inventory</title>
</head>
<body bgcolor="white">
<center>
Welcome
<font color="red">
On Sale Today ...
</font>
<p></p>
<xsltlib:apply xml="cdcatalog.xml" xsl="cdcatalog.xsl"/>
</center>
</body>
</html>org.apache.jasper.JasperException: Unable to open
taglibrary http://jakarta.apache.org/taglibs/xsl-1.0 :
nullWell, like the first answer to your post, it's like the error message says:
The file ist not there! Try to open it with your browser and you'll get an error message.
I think, it's not a good idea to reference remote URLs, because not everyone got a dedicated line. So download the xsl-taglib from
http://jakarta.apache.org/builds/jakarta-taglibs/nightly/projects/xsl/
The documentation and all other stuff is located at
http://jakarta.apache.org/taglibs/doc/xsl-doc/intro.html
Hope this helps.
Maybe you are looking for
-
Powershell script to get the list of pages using a particular webpart in SharePoint 2013
I want to find all the pages withing a web application or site collection on which particular webpart is enabled. I have seen the link http://www.glynblogs.com/2011/07/listing-all-web-parts-in-a-site-collection-with-powershell.html but it doesnt wor
-
How to convert and download Vide
I have a Zen 4GB MP3 player and I don't know how to convert videos or download videos to my Zen Is there any specific site I have to download/convert ?videos?
-
Airport Update Problems-Where's Apple?
I am not here to flame Apple but I know they have Mods on this board that should be able to answer my question. Is there an official message from Apple on what users like me should do now that my $2000 laptop is no longer useful for me when I travel?
-
Hello All the contributors, plz to give me a right solution, Req_urjent. Query: with PO against Sales order ( indvidual purchase order_ sales process.) with ref PO- raised sales order, and also delivery with PGI, but when raised a sls order customer
-
How to use phone when screen is shattered?
dropped iphone, screen cracked/shattered-can't slide to unlock-Is there another way to unlock the phone?