Discussions

Web tier: servlets, JSP, Web frameworks: No such Method Error (JSP)--debug for 2 days , still cant solve

  1. Below is a very simple normal class that i create to be used in jsp:
    -----------------------------------------------------
    package com;
    public class Product{
    private int pdtId;
    private String pdtName;
    private int price;
    private int quantity;
    public Product(int pdtId, int quantity, String pdtName, int price ){
    this.pdtId=pdtId;
    this.price=price;
    this.quantity=quantity;
    this.pdtName=pdtName;
    }
               
            public int getPdtId(){return pdtId;}
            public String getPdtName(){ return pdtName;}
            public int getPrice(){return price;}
            public int getQuantity(){return quantity;}
    }
    ---------------------------------------------------------
    I wrote a simple jsp:

    <%@ page session="true" contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*,javax.sql.*,javax.naming.*,com.*,java.util.*" errorPage="" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <body>
    <%
       session.setAttribute("rr",new Product(1,1,"3",4));
       Product p=(Product)(session.getAttribute("rr"));
       
       
     
    %>
    <%=p.getPrice()%> //note that problem occur here
    </body>
    </html>
    ------------------------------------------------
    The problem is the server can't find the method getPrice in the product class??Why is that so? I quite sure server know the existence of my Product class...2nd question, is it ok to have the session set an attribute, and then get the attribute from the session in one single activation,as wat i done above??
  2. The most common cause of this error is having your artifacts out of date, meaning your class Product at one time did not have a getPrice method and it is that class that is still in primary Product class in your class path. I suggest making sure that the new compiled version of Product are REALLY ending up in the right place for the server to see.