User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JSP section within the Web Development category of DaniWeb, a massive community of 456,601 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,481 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JSP advertiser: Lunarpages JSP Web Hosting
Views: 2587 | Replies: 0 | Solved
Reply
Join Date: Nov 2006
Posts: 38
Reputation: apontutul is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 1
apontutul's Avatar
apontutul apontutul is offline Offline
Light Poster

getting parameters from jsp...plz help

  #1  
Sep 11th, 2007
i want to show a image using servlet,which is being called by a java file (beans).
in that java how will i get the parameter eg: poll-id=1,2 or 3...n from that jsp page?....here what i've done(.java file) but the its not showing the image(error: data not available):

package myapp.webwork.beans;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.*;
import org.jfree.data.jdbc.*;
import org.jfree.data.general.*;

import java.io.*;
import java.awt.*;
import java.util.*;
import java.awt.image.*;
import org.jfree.data.*;
import org.jfree.chart.*;
import org.jfree.chart.plot.*;
import org.jfree.chart.urls.*;
import org.jfree.chart.entity.*;
import javax.servlet.*;
import javax.servlet.http.*;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities.*;
import org.jfree.chart.imagemap.*;
import java.io.PrintWriter.*;
import java.lang.String.*;
import java.lang.Integer.*;
import org.jfree.chart.ChartRenderingInfo.*;



public class votepie {
    
    Connection con;
    PreparedStatement st;
    ResultSet rs;
    //int id;
    
    /**
     * @param args
     */
        
    public PieDataset readData(int id) {
        
        JDBCPieDataset data = null;
        String url = "jdbc:mysql://localhost/vote";
        //Connection con;
        try {
        Class.forName("com.mysql.jdbc.Driver");
        }
        catch (ClassNotFoundException e) {
        System.err.print("ClassNotFoundException: ");
        System.err.println(e.getMessage());
        }
         
        try {
            
            //id = rs.getString("poll_id");
        con = DriverManager.getConnection(url, "vote", "vote001");
        data = new JDBCPieDataset(con);
                
        st = con.prepareStatement("SELECT option_text, counter FROM VOTE_VOTES where poll_id=?");
        
        //PreparedStatement st= con.prepareStatement(sql);
        st.setInt(1, id);
        rs = st.executeQuery();
                
        //data.executeQuery(sql);
        con.close();
        st.close();
        rs.close();
        }
        catch (SQLException e) {
        System.err.print("SQLException: ");
        System.err.println(e.getMessage());
        }
        catch (Exception e) {
        System.err.print("Exception: ");
        System.err.println(e.getMessage());
        }
        return data;
        }
    
    
    public String getvoteserve(HttpServletRequest request, HttpServletResponse response) {
        votepie pd = new votepie();
        int id = new Integer (request.getParameter("poll_id"));
    
        // create the chart...
        JFreeChart chart = ChartFactory.createPieChart(
              "Vote Result Pie Chart",  // chart title
              pd.readData(id),             // data
              true,                // include legend
              true,
              false
        );

        // set the background color for the chart...
        chart.setBackgroundPaint(Color.cyan);
        PiePlot plot = (PiePlot) chart.getPlot();
        plot.setNoDataMessage("No data available");
         
        
        // OPTIONAL CUSTOMISATION COMPLETED.

        ChartRenderingInfo info = null;
        HttpSession session = request.getSession();
        try {

          //Create RenderingInfo object
          response.setContentType("text/html");
          info = new ChartRenderingInfo(new StandardEntityCollection());
          BufferedImage chartImage = chart.createBufferedImage(640, 400, info);

          // putting chart as BufferedImage in session, 
          // thus making it available for the image reading action Action.
          session.setAttribute("chartImage", chartImage);

          PrintWriter writer = new PrintWriter(response.getWriter());
          ChartUtilities.writeImageMap(writer, "imageMap", info, true);
          writer.flush();
        
        }
        catch (Exception e) {
           // handle your exception here
        }
       
        String pathInfo = "http://";
        pathInfo += request.getServerName();
        int port = request.getServerPort();
        pathInfo += ":"+String.valueOf(port);
        pathInfo += request.getContextPath();
        String chartViewer = pathInfo + "/servlet/voteserve";
        return chartViewer;
      }
    }

another thinh when I put thvalue of the "poll_id" manually into the SQL query the image is being shown. so may be the prob lies here. or is it so?....plz kindly suggest what to do....
AddThis Social Bookmark Button
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JSP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the JSP Forum

All times are GMT -4. The time now is 7:04 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC