try
{
response.setContentType(contentType);
response.getOutputStream().flush();
TransformerFactory tFactory = TransformerFactory.newInstance();
String str = OptionsXML.getOptionsXML(pageType, language, country,response);
StringReader sReader = new StringReader(str);
StreamSource xml = new StreamSource(sReader) ;
StreamSource xsl = new StreamSource(xslName) ;
Transformer transformer = tFactory.newTransformer(xsl);
StreamResult result = new StreamResult(response.getOutputStream()) ;
transformer.transform(xml, result);
}
catch(Exception e)
{}
Option.jsp 代码
<%@ page import="java.util.*" %>
<%@ page import="java.net.*" %>
<%@ page import="import org.xml.sax.*" %>
<%@ page import="javax.xml.transform.TransformerFactory" %>
<%@ page import="javax.xml.transform.Transformer" %>
<%@ page import="javax.xml.transform.stream.StreamSource" %>
<%@ page import="javax.xml.transform.stream.StreamResult" %>
<%@ page import="javax.xml.transform.TransformerException" %> #p#分页标题#e# <%@ page import="javax.xml.transform.TransformerConfigurationException" %>
<%@ page import="wayne.articles.xmlgen.*"%>
<% String pageType="Web";
String userAgent = request.getHeader("User-Agent");
String contentType="text/html;charset=UTF-8";
String xslName="articles-html-form.xsl";
String language="en";
String country="US";
if((language = request.getParameter("language"))==null)
language="en";
if((country = request.getParameter("country"))==null)
country="US";
country = country.toUpperCase();
if(userAgent.startsWith("Mozilla")) {
pageType="Web";
contentType="text/html;charset=UTF-8";
xslName="articles-html-form.xsl";
}
else if(userAgent.startsWith("Microsoft URL")) {
pageType="IMode";
contentType="text/html;charset=UTF-8";
xslName="articles-imode-form.xsl";
}
else if(userAgent.startsWith("Nokia"))
{
pageType="Wap";
contentType="text/vnd.wap.wml";
xslName="articles-wml-form.xsl";
}
showPage(pageType,language,country, response, contentType, xslName);
%>
<%
private void showPage(String pageType, String language, String country, HttpServletResponse response,String contentType, String xslName)
{
try
{
response.setContentType(contentType);
response.getOutputStream().flush();
TransformerFactory tFactory = TransformerFactory.newInstance();
String str = OptionsXML.getOptionsXML(pageType, language, country,response);
StringReader sReader = new StringReader(str);
StreamSource xml = new StreamSource(sReader) ;
StreamSource xsl = new StreamSource(xslName) ;
Transformer transformer = tFactory.newTransformer(xsl);
StreamResult result = new StreamResult(response.getOutputStream()) ;
transformer.transform(xml, result);
}
catch(Exception e)
{}
}
%>
YourResponse.jsp 代码:
<%@ page import="java.util.*" %>
<%@ page import="java.net.*" %>
<%@ page import="import org.xml.sax.*" %>
<%@ page import="javax.xml.transform.TransformerFactory" %>
<%@ page import="javax.xml.transform.Transformer" %>
<%@ page import="javax.xml.transform.stream.StreamSource" %>
<%@ page import="javax.xml.transform.stream.StreamResult" %>
<%@ page import="javax.xml.transform.TransformerException" %>
<%@ page import="javax.xml.transform.TransformerConfigurationException" %>
<%@ page import="wayne.articles.xmlgen.*"%>
<%
String pageType="Web";
String userAgent = request.getHeader("User-Agent");
String contentType="text/html;charset=UTF-8";
String xslName="articles-html-form.xsl";
String language="en";
String country="US";
if((language = request.getParameter("language"))==null)
language="en";
if((country = request.getParameter("country"))==null)
country="US";
country = country.toUpperCase();
int optionid = 1;
try
{
optionid = Integer.parseInt(request.getParameter("optionType"));
}
catch(Exception e)
{
optionid = 1;
}
System.out.println("user Agent = " + userAgent);
if(userAgent.startsWith("Mozilla"))
{
pageType="Web";
contentType="text/html;charset=UTF-8";
xslName="articles-html-form.xsl";
}
else if(userAgent.startsWith("Microsoft URL"))
{
System.out.println("entered");
pageType="IMode";
contentType="text/html;charset=UTF-8";
xslName="articles-imode-form.xsl";
}
else if(userAgent.startsWith("Nokia"))
{
pageType="Wap";
contentType="text/vnd.wap.wml";
xslName="articles-wml-form.xsl";
}
showPage(pageType,language,country, response, optionid, contentType, xslName);
%>
<% #p#分页标题#e# private void showPage(String pageType,String language,String country, HttpServletResponse response, int optionid,String contentType, String xslName)
{
try
{
response.setContentType(contentType);
response.getOutputStream().flush();
TransformerFactory tFactory = TransformerFactory.newInstance();
String str = YourResponseXML.getYourResponseXML(pageType,language,country,response, optionid);
StringReader sReader = new StringReader(str);
StreamSource xml = new StreamSource(sReader) ;
StreamSource xsl = new StreamSource(xslName) ;
Transformer transformer = tFactory.newTransformer(xsl);
StreamResult result = new StreamResult(response.getOutputStream()) ;
transformer.transform(xml, result); } catch(Exception e){}
}
%> |
|