Stewart Johnson

Greenhorn
+ Follow
since Dec 11, 2006
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Stewart Johnson

import javax.xml.transform.sax.SAXSource;
import org.xml.sax.helpers.XMLReaderFactory;
import org.xml.sax.XMLReader;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.Result;


import java.io.*;
import java.net.*;
import java.util.*;

import javax.servlet.*;
import javax.servlet.http.*;

public class TransformServlet extends HttpServlet {

private InputStream sXmlFilePath;
private InputStream sXSLFilePath;
private static final String parserClass = "org.apache.xerces.parsers.SAXParser";


protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

ServletContext sc = getServletContext();
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();



sXmlFilePath = sc.getResourceAsStream("/xml/yourxml.xml");
sXSLFilePath = sc.getResourceAsStream("/xsl/yourxsl.xsl");

try{
XMLReader reader = XMLReaderFactory.createXMLReader(parserClass);
Source source = new SAXSource(reader, new InputSource(sXmlFilePath));
Source style = new StreamSource(sXSLFilePath);
TransformerFactory transFactory = TransformerFactory.newInstance();
Transformer trans = transFactory.newTransformer(style);
StreamResult result = new StreamResult(new StringWriter());
trans.transform(source, result);
String htmlString = result.getWriter().toString();
out.write(htmlString);
}catch(SAXException se){

System.out.println("SAXException"+se);

}catch(TransformerConfigurationException tce){

System.out.println("TransformerConfigurationException"+tce);

}catch(TransformerException te){
System.out.println("TransformerException"+te);

}

}


protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}

protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}

public String getServletInfo() {
return "Short description";
}
// </editor-fold>
}
Use cutom tag for footer
18 years ago
JSP
Thanks, the place where the value comes back to the Screen is from a context defined BAPI node in SAP WebDynpro application. The table cells themselves are binded to the context nodes. Not sure how I will format the value there, and I suppose that is a SAP forum question. Thanks again for all the replies!
18 years ago
Thanks, that does work and gives me the correct output. Now the new problem is passing for example "3965.00" to the constructor of a BigDecimal

For example:

setNet_Price(new BigDecimal("3695.00"));

in this case, the .00 is removed

how can I stop the new BigDecimal("3695.00") from removing the zero's? it does not rmove decimal places othe than .00

Thanks!
18 years ago
Hi,

I am working on a problem where I have to format a number with two decimalplaces. Here is an 3example of how I am trying to do this:

NumberFormat formatter = new DecimalFormat("#.##");
String s = formatter.format(item.getPrice());
double testPrice = Double.parseDouble(s);
System.out.println(""+testPrice );

the problem is that when there are no decimal places in the price, the formatter only ads one zero whereas I need two decimal places like .00 to meet the busiiness requirement.

Thanks for your help.
[ December 11, 2006: Message edited by: Stewart Johnson ]
18 years ago