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 402,550 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 2,304 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: 1559 | Replies: 3 | Solved
Reply
Join Date: Nov 2006
Posts: 38
Reputation: apontutul is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 1
apontutul's Avatar
apontutul apontutul is offline Offline
Light Poster

Solution errors regarding java code in jsp page. help me please

  #1  
Sep 3rd, 2007
hi guys......i want to view a piechart extracting items from a mysql database. i've created a button on a jsp page(view.jsp) which is calling another jsp page(viewrst.jsp) when i click that. the code for (viewrst.jsp) is given below:
<%@ page language="java"%>
 
<%@page import="org.jfree.chart.*;"%>
<%@page import="java.sql.DriverManager;"%>
<%@page import="java.sql.*;"%>
<%@page import="org.jfree.data.jdbc.*;"%>
<%@page import="org.jfree.data.general.*;"%>
 
<%!
public class votepie {
 
    /**
     * @param args
     */
    
    private PieDataset readData() {
        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 {
        con = DriverManager.getConnection(url, "vote", "vote001");
        data = new JDBCPieDataset(con);
        String sql = "SELECT option_text, counter FROM VOTE_VOTES where poll_id=1;";
        data.executeQuery(sql);
        con.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 static void main(String[] args) {
        // TODO Auto-generated method stub
        
        votepie pd = new votepie();
        pd.readData();
        
        //creating the chart
        JFreeChart chart = ChartFactory.createPieChart(
                "Sample Pie Chart",
                pd.readData(),
                true, // legend?
                true, // tooltips?
                false // URLs?
                );
                // create and display a frame...
                ChartFrame frame = new ChartFrame("First", chart);
                frame.pack();
                frame.setVisible(true);
 
    }
 
}
%>

& i'm getting this error when I click the button:
HTTP Status 500 - 

type Exception report
message 
description The server encountered an internal error () that prevented it from fulfilling this request.
exception 
org.apache.jasper.JasperException: Unable to compile class for JSP: 





An error occurred at line: 44 in the jsp file: /viewrst.jsp
The method main cannot be declared static; static methods can only be declared in a static or top level type
41:         }
42:         return data;
43:         }
44:     public static void main(String[] args) {
45:         // TODO Auto-generated method stub
46:         
47:         votepie pd = new votepie();


Stacktrace:
    org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:85)
    org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
    org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:415)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:308)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:273)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:308)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.10 logs.
Apache Tomcat/6.0.10


is the prob related to classpath variables?the java is working when i run it, but not in jsp. please suggest what to do?......thankz.
Last edited by apontutul : Sep 3rd, 2007 at 4:55 pm.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2004
Location: London or Slovakia
Posts: 2,230
Reputation: peter_budo is a jewel in the rough peter_budo is a jewel in the rough peter_budo is a jewel in the rough 
Rep Power: 10
Solved Threads: 270
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: errors regarding java code in jsp page. help me please

  #2  
Sep 3rd, 2007
Hmmmmm interesting, I would never say that main method bellong to JSP...
...or is this new programming approach?
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

If we helped you to solve your problem, answered your question please mark your post as SOLVED.
Reply With Quote  
Join Date: Nov 2006
Posts: 38
Reputation: apontutul is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 1
apontutul's Avatar
apontutul apontutul is offline Offline
Light Poster

Re: errors regarding java code in jsp page. help me please

  #3  
Sep 4th, 2007
ok..but when I remove "static" from there the error is not shown anymore!...what is going on,what to do then???? i'm confused
Reply With Quote  
Join Date: Dec 2004
Location: London or Slovakia
Posts: 2,230
Reputation: peter_budo is a jewel in the rough peter_budo is a jewel in the rough peter_budo is a jewel in the rough 
Rep Power: 10
Solved Threads: 270
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: errors regarding java code in jsp page. help me please

  #4  
Sep 4th, 2007
JSP has no "main" method in its body!
If you wish to execute something you should use SERVLET and outcome pass to another JSP page. You may want to have go on this tutorial http://java.sun.com/javaee/5/docs/tutorial/doc/
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

If we helped you to solve your problem, answered your question please mark your post as SOLVED.
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 9:10 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC