系统原型结构描述(七)

 

IndexHelpAction.java

 

package com.test.action.help;

import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class IndexHelpAction extends ActionSupport {
 public String execute() {
  ActionContext ct= ActionContext.getContext();

  Map session = ct.getSession();
  
  session.put("hello", "hello world!");
  
  System.out.println( session.size()+ " " + session);
 
  
  
  
  return SUCCESS;
 }
}


IndexViewProcessAction.java

package com.test.action.view;

import java.util.List;

import com.opensymphony.xwork2.ActionSupport;
import com.test.page.PageManager;
import com.test.page.PageValue;

public class IndexViewProcessAction extends ActionSupport {
 private PageManager pageManager = null;
 private List list = null;
 public int current;
 public PageValue page = new PageValue();

 public String execute() {
  //list = this.bookService.selectAllBooks(0, this.bookService.getBookTotal

());
  
  page.setCurrent(current);
  page = this.pageManager.run(page);
  list = page.getResult();
  
  return SUCCESS;
 }
 public PageManager getPageManager() {
  return pageManager;
 }
 public void setPageManager(PageManager pageManager) {
  this.pageManager = pageManager;
 }
 public int getCurrent() {
  return current;
 }
 public void setCurrent(int current) {
  this.current = current;
 }
 public PageValue getPage() {
  return page;
 }
 public void setPage(PageValue page) {
  this.page = page;
 }
 public List getList() {
  return list;
 }
 public void setList(List list) {
  this.list = list;
 }
}

 

DisplayChart.java

 

 

/* ===========================================================
 * JFreeChart : a free chart library for the Java(tm) platform
 * ===========================================================
 *
 * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors.
 *
 * Project Info:  http://www.jfree.org/jfreechart/index.html
 *
 * This library is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
 * License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
 * USA. 
 *
 * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
 * in the United States and other countries.]
 *
 * -----------------
 * DisplayChart.java
 * -----------------
 * (C) Copyright 2002-2007, by Richard Atkinson and Contributors.
 *
 * Original Author:  Richard Atkinson;
 * Contributor(s):   David Gilbert (for Object Refinery Limited);
 *
 * Changes
 * -------
 * 19-Aug-2002 : Version 1;
 * 09-Mar-2005 : Added facility to serve up "one time" charts - see
 *               ServletUtilities.java (DG);
 * ------------- JFREECHART 1.0.x ---------------------------------------------
 * 02-Feb-2007 : Removed author tags all over JFreeChart sources (DG);
 *
 */

package com.test.action.view.chart;

import java.io.File;
import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.jfree.chart.servlet.ChartDeleter;
import org.jfree.chart.servlet.ServletUtilities;

/**
 * Servlet used for streaming charts to the client browser from the temporary
 * directory.  You need to add this servlet and mapping to your deployment
 * descriptor (web.xml) in order to get it to work.  The syntax is as follows:
 * <xmp>
 * <servlet>
 *    <servlet-name>DisplayChart</servlet-name>
 *    <servlet-class>org.jfree.chart.servlet.DisplayChart</servlet-class>
 * </servlet>
 * <servlet-mapping>
 *     <servlet-name>DisplayChart</servlet-name>
 *     <url-pattern>/servlet/DisplayChart</url-pattern>
 * </servlet-mapping>
 * </xmp>
 */
public class DisplayChart extends HttpServlet {

    /**
     * Default constructor.
     */
    public DisplayChart() {
        super();
    }

    /**
     * Init method.
     *
     * @throws ServletException never.
     */
    public void init() throws ServletException {
        return;
    }

    /**
     * Service method.
     *
     * @param request  the request.
     * @param response  the response.
     *
     * @throws ServletException ??.
     * @throws IOException ??.
     */
    public void service(HttpServletRequest request,
                        HttpServletResponse response)
            throws ServletException, IOException {

        HttpSession session = request.getSession();
        String filename = request.getParameter("filename");

        if (filename == null) {
            throw new ServletException("Parameter 'filename' must be supplied");
        }

        //  Replace ".." with ""
        //  This is to prevent access to the rest of the file system
        filename = ServletUtilities.searchReplace(filename, "..", "");

        //  Check the file exists
        File file = new File(System.getProperty("java.io.tmpdir"), filename);
        if (!file.exists()) {
            throw new ServletException("File '" + file.getAbsolutePath()
                    + "' does not exist");
        }

        //  Check that the graph being served was created by the current user
        //  or that it begins with "public"
        boolean isChartInUserList = false;
        ChartDeleter chartDeleter = (ChartDeleter) session.getAttribute(
                "JFreeChart_Deleter");
        if (chartDeleter != null) {
            isChartInUserList = chartDeleter.isChartAvailable(filename);
        } else {
         isChartInUserList = true;
        }

        boolean isChartPublic = false;
        if (filename.length() >= 6) {
            if (filename.substring(0, 6).equals("public")) {
                isChartPublic = true;
            }
        }
       
        boolean isOneTimeChart = false;
        if (filename.startsWith(ServletUtilities.getTempOneTimeFilePrefix())) {
            isOneTimeChart = true;  
        }

        if (isChartInUserList || isChartPublic || isOneTimeChart) {
            //  Serve it up
            ServletUtilities.sendTempFile(file, response);
            if (isOneTimeChart) {
                file.delete();  
            }
        }
        else {
            throw new ServletException("Chart image not found");
        }
        return;
    }

}

 


IndexChartProcessAction.java

 

 

package com.test.action.view.chart;

import java.io.IOException;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.math.RandomUtils;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.interceptor.SessionAware;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.StandardXYItemRenderer;
import org.jfree.chart.servlet.ServletUtilities;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.test.logic.service.BookService;

public class IndexChartProcessAction extends ActionSupport implements SessionAware {
 private BookService bookService = null;
 public JFreeChart chart;
 
 public BookService getBookService() {
  return bookService;
 }
 public void setBookService(BookService bookService) {
  this.bookService = bookService;
 }
 public String execute() {

  XYSeries dataSeries = new XYSeries(new Integer(1));
  for(int i = 0; i <= 1000; i++) {
   dataSeries.add(i, RandomUtils.nextInt());
  }
  XYSeriesCollection xyDataset = new XYSeriesCollection(dataSeries);
  
  ValueAxis xAxis = new NumberAxis("Raw Marks");
  ValueAxis yAxis = new NumberAxis("Moderated Marks");
  
  chart =
   new JFreeChart (
     "Moderation Function",
     JFreeChart.DEFAULT_TITLE_FONT,
     new XYPlot(
       xyDataset,
       xAxis,
       yAxis,
       new StandardXYItemRenderer

(StandardXYItemRenderer.LINES)),
       false);
  chart.setBackgroundPaint(java.awt.Color.white);
  ActionContext ctx = ActionContext.getContext();
  HttpServletRequest request = (HttpServletRequest)ctx.get

(ServletActionContext.HTTP_REQUEST);       
 
  
  try {
   request.setAttribute("filename", ServletUtilities.saveChartAsPNG

(chart, 400, 300, request.getSession()));
   System.out.println(request.getSession().getId());

  } catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  
  return SUCCESS;
 }
 public JFreeChart getChart() {
  return chart;
 }
 public void setChart(JFreeChart chart) {
  this.chart = chart;
 }
 public void setSession(Map arg0) {
  // TODO Auto-generated method stub
  
 }
}


 

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值