owPage(pageType, language, country, response, contentType, xslName);
showPage()方法根据pageType、语言和国家设置来产生XML页面。 它应用特定的XSLT样式表来生成XML然后把格式化了的应答发回用户设备。
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" %>
<%@ 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 Stream
|