public class DashboardServlet extends HttpServlet {
protected void processRequest(HttpServletRequest request
, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8"); getWeatherForecast(request, response);
getStockQuotes(request, response);
getNewsItems(request, response);
request.getRequestDispatcher("/jsp/ajaxDashboard.jsp")
.forward(request, response);
}
private void getWeatherForecast(HttpServletRequest request
, HttpServletResponse response) throws ServletException, IOException {
WeatherForecastService forecastService = new WeatherForecastService();
request.setAttribute("forecastData"
, forecastService.getForecastFor(Constants.DEFAULT_WEATHER_ZIP_CODE));
}
private void getStockQuotes(HttpServletRequest request
, HttpServletResponse response) throws ServletException, IOException { GetQuotesResponse quotesResponse =
new StockQuoteService()
.getStockQuotesFor(Constants.DEFAULT_STOCK_TICKERS);
Quote[] quotesArray = quotesResponse.getGetQuotesResult().getQuote();
request.setAttribute("quotesArray", quotesArray);
}
private void getNewsItems(HttpServletRequest request
, HttpServletResponse response) throws ServletException, IOException {
Collection newsItems = new NewsService().getNewsItems();
request.setAttribute("newsItems", newsItems);
}
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);
}
}部分代码
protected void processRequest(HttpServletRequest request
, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8"); getWeatherForecast(request, response);
getStockQuotes(request, response);
getNewsItems(request, response);
request.getRequestDispatcher("/jsp/ajaxDashboard.jsp")
.forward(request, response);
}
private void getWeatherForecast(HttpServletRequest request
, HttpServletResponse response) throws ServletException, IOException {
WeatherForecastService forecastService = new WeatherForecastService();
request.setAttribute("forecastData"
, forecastService.getForecastFor(Constants.DEFAULT_WEATHER_ZIP_CODE));
}
private void getStockQuotes(HttpServletRequest request
, HttpServletResponse response) throws ServletException, IOException { GetQuotesResponse quotesResponse =
new StockQuoteService()
.getStockQuotesFor(Constants.DEFAULT_STOCK_TICKERS);
Quote[] quotesArray = quotesResponse.getGetQuotesResult().getQuote();
request.setAttribute("quotesArray", quotesArray);
}
private void getNewsItems(HttpServletRequest request
, HttpServletResponse response) throws ServletException, IOException {
Collection newsItems = new NewsService().getNewsItems();
request.setAttribute("newsItems", newsItems);
}
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);
}
}部分代码
package ajaxdashboard.service;import ajaxdashboard.ws.stockquote.GetQuotes;
import ajaxdashboard.ws.stockquote.GetQuotesResponse;
import ajaxdashboard.ws.stockquote.Quote;
import ajaxdashboard.ws.stockquote.StockQuotesLocator;
import ajaxdashboard.ws.stockquote.StockQuotesSoap;
import javax.xml.rpc.ServiceException;public class StockQuoteService { public GetQuotesResponse getStockQuotesFor(String ticker) {
GetQuotes quotes = new GetQuotes(ticker);
GetQuotesResponse quotesResponse = null;
try {
quotesResponse = getStockQuotesSoap().getStockQuotes(quotes);
} catch(java.rmi.RemoteException ex) {
// TODO handle remote exception
}
Quote[] quotesArray = quotesResponse.getGetQuotesResult().getQuote();
Quote quote = null;
for(int i = 0; i < quotesArray.length; i++) {
quote = quotesArray[i];
// System.out.println("Quote for: " + quote.getCompanyName()
// + " (" + quote.getStockTicker()+ ")"
// + "\nQuote:" + quote.getStockQuote()
// + "\nLastUpdate:" + quote.getLastUpdated()
// + "\nChange:" + quote.getChange());
} return quotesResponse;
} private StockQuotesSoap getStockQuotesSoap() {
StockQuotesSoap stockQuotesSoap = null;
try {
stockQuotesSoap = new StockQuotesLocator().getStockQuotesSoap();
} catch (ServiceException ex) {
ex.printStackTrace();
}
return stockQuotesSoap;
}
}
quotesResponse.getGetQuotesResult().getQuote();请把 Tomcat/5.5.17 logs 下面的详细错误日志贴出来做进一步分析。
信息: org.apache.webapp.balancer.BalancerFilter: init(): ruleChain: [org.apache.webapp.balancer.RuleChain: [org.apache.webapp.balancer.rules.URLStringMatchRule: Target string: News / Redirect URL: http://www.cnn.com], [org.apache.webapp.balancer.rules.RequestParameterRule: Target param name: paramName / Target param value: paramValue / Redirect URL: http://www.yahoo.com], [org.apache.webapp.balancer.rules.AcceptEverythingRule: Redirect URL: http://jakarta.apache.org]]
2006-5-9 9:23:59 org.apache.catalina.core.ApplicationContext log
信息: ContextListener: contextInitialized()
2006-5-9 9:23:59 org.apache.catalina.core.ApplicationContext log
信息: SessionListener: contextInitialized()
2006-5-9 9:24:03 org.apache.catalina.core.ApplicationContext log
信息: ContextListener: contextInitialized()
2006-5-9 9:24:03 org.apache.catalina.core.ApplicationContext log
信息: SessionListener: contextInitialized()
2006-5-9 10:25:43 org.apache.catalina.core.ApplicationContext log
信息: org.apache.webapp.balancer.BalancerFilter: init(): ruleChain: [org.apache.webapp.balancer.RuleChain: [org.apache.webapp.balancer.rules.URLStringMatchRule: Target string: News / Redirect URL: http://www.cnn.com], [org.apache.webapp.balancer.rules.RequestParameterRule: Target param name: paramName / Target param value: paramValue / Redirect URL: http://www.yahoo.com], [org.apache.webapp.balancer.rules.AcceptEverythingRule: Redirect URL: http://jakarta.apache.org]]
2006-5-9 10:25:45 org.apache.catalina.core.ApplicationContext log
信息: ContextListener: contextInitialized()
2006-5-9 10:25:45 org.apache.catalina.core.ApplicationContext log
信息: SessionListener: contextInitialized()
2006-5-9 10:25:47 org.apache.catalina.core.ApplicationContext log
信息: ContextListener: contextInitialized()
2006-5-9 10:25:47 org.apache.catalina.core.ApplicationContext log
信息: SessionListener: contextInitialized()
2006-5-9 13:32:42 org.apache.catalina.core.ApplicationContext log
信息: SessionListener: contextDestroyed()
2006-5-9 13:32:42 org.apache.catalina.core.ApplicationContext log
信息: ContextListener: contextDestroyed()
2006-5-9 13:32:50 org.apache.catalina.core.ApplicationContext log
信息: SessionListener: contextDestroyed()
2006-5-9 13:32:50 org.apache.catalina.core.ApplicationContext log
信息: ContextListener: contextDestroyed()
2006-5-9 13:45:04 org.apache.catalina.core.ApplicationContext log
信息: org.apache.webapp.balancer.BalancerFilter: init(): ruleChain: [org.apache.webapp.balancer.RuleChain: [org.apache.webapp.balancer.rules.URLStringMatchRule: Target string: News / Redirect URL: http://www.cnn.com], [org.apache.webapp.balancer.rules.RequestParameterRule: Target param name: paramName / Target param value: paramValue / Redirect URL: http://www.yahoo.com], [org.apache.webapp.balancer.rules.AcceptEverythingRule: Redirect URL: http://jakarta.apache.org]]
2006-5-9 13:45:09 org.apache.catalina.core.ApplicationContext log
信息: ContextListener: contextInitialized()
2006-5-9 13:45:09 org.apache.catalina.core.ApplicationContext log
信息: SessionListener: contextInitialized()
2006-5-9 13:45:10 org.apache.catalina.core.ApplicationContext log
信息: ContextListener: contextInitialized()
2006-5-9 13:45:10 org.apache.catalina.core.ApplicationContext log
信息: SessionListener: contextInitialized()
2006-5-9 14:30:57 org.apache.catalina.core.ApplicationContext log
信息: org.apache.webapp.balancer.BalancerFilter: init(): ruleChain: [org.apache.webapp.balancer.RuleChain: [org.apache.webapp.balancer.rules.URLStringMatchRule: Target string: News / Redirect URL: http://www.cnn.com], [org.apache.webapp.balancer.rules.RequestParameterRule: Target param name: paramName / Target param value: paramValue / Redirect URL: http://www.yahoo.com], [org.apache.webapp.balancer.rules.AcceptEverythingRule: Redirect URL: http://jakarta.apache.org]]
2006-5-9 14:30:58 org.apache.catalina.core.ApplicationContext log
信息: ContextListener: contextInitialized()
2006-5-9 14:30:58 org.apache.catalina.core.ApplicationContext log
信息: SessionListener: contextInitialized()
2006-5-9 14:30:59 org.apache.catalina.core.ApplicationContext log
信息: ContextListener: contextInitialized()
2006-5-9 14:30:59 org.apache.catalina.core.ApplicationContext log
信息: SessionListener: contextInitialized()
2006-5-9 15:27:16 org.apache.catalina.core.ApplicationContext log
信息: SessionListener: contextDestroyed()
2006-5-9 15:27:16 org.apache.catalina.core.ApplicationContext log
信息: ContextListener: contextDestroyed()
2006-5-9 15:27:24 org.apache.catalina.core.ApplicationContext log
信息: SessionListener: contextDestroyed()
2006-5-9 15:27:24 org.apache.catalina.core.ApplicationContext log
信息: ContextListener: contextDestroyed()
2006-5-9 21:41:38 org.apache.catalina.core.ApplicationContext log
信息: org.apache.webapp.balancer.BalancerFilter: init(): ruleChain: [org.apache.webapp.balancer.RuleChain: [org.apache.webapp.balancer.rules.URLStringMatchRule: Target string: News / Redirect URL: http://www.cnn.com], [org.apache.webapp.balancer.rules.RequestParameterRule: Target param name: paramName / Target param value: paramValue / Redirect URL: http://www.yahoo.com], [org.apache.webapp.balancer.rules.AcceptEverythingRule: Redirect URL: http://jakarta.apache.org]]
2006-5-9 21:41:39 org.apache.catalina.core.ApplicationContext log
信息: ContextListener: contextInitialized()
2006-5-9 21:41:39 org.apache.catalina.core.ApplicationContext log
信息: SessionListener: contextInitialized()
2006-5-9 21:41:40 org.apache.catalina.core.ApplicationContext log
信息: ContextListener: contextInitialized()
2006-5-9 21:41:40 org.apache.catalina.core.ApplicationContext log
信息: SessionListener: contextInitialized()
2006-5-9 22:58:42 org.apache.catalina.core.ApplicationContext log
信息: SessionListener: contextDestroyed()
2006-5-9 22:58:42 org.apache.catalina.core.ApplicationContext log
信息: ContextListener: contextDestroyed()
2006-5-9 22:58:50 org.apache.catalina.core.ApplicationContext log
信息: SessionListener: contextDestroyed()
2006-5-9 22:58:50 org.apache.catalina.core.ApplicationContext log
信息: ContextListener: contextDestroyed()日志