• Post Reply Bookmark Topic Watch Topic
  • New Topic

Error while calling a non static method of Core java from JSP page  RSS feed

 
munish gupta
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I am calling a non static method from index.jsp page.
I am getting error.
after making the method static I am able to compile and run.

Why m not able to call a non static java method on JSP page???

Thanks
Munish
 
Prasad Krishnegowda
Ranch Hand
Posts: 672
4
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Show us the code.

P:S: Are you using Java code inside JSP? If Yes, don't do that, it was discredited 10 Years back..
 
munish gupta
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


The fields are taken from db like:

Cities are in 1 field
cities are mapped against some product codes using HashMap
product codes are maped along with the attributes of products in Hash Map
So that
according to city , products can be taken.
according to product code, product's attribute can be identified

--------------
CODE -------------------------------

<%! List<String> storesList = new ArrayList<String>(); %>


<%
ProductsByCities pbc= new ProductsByCities();
storesList = pbc.getCityList(); // List contains the cities list taken from Database
//getCityList is Non-static method
%>

later on fetching the storesList into option[] of select in HTML.

Its working fine if code is like :

<%
storesList = ProductsByCities .getCityList(); //getCityList is static method %>

 
Prasad Krishnegowda
Ranch Hand
Posts: 672
4
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should not be using scriptlets inside JSP, move the logic to Servlet and use JSTL/EL to access the variables.
I have no idea, why that's not working. I have not written any java codes inside JSP..
 
Amit Bariar
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<%
ProductsByCities pbc= new ProductsByCities();
storesList = pbc.getCityList(); // List contains the cities list taken from Database
//getCityList is Non-static method
%>


above code should run if getCityList() method is public...
but the best way to write this java code in other java class and call it using tag libs
 
munish gupta
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Prasad

I think Scriplets can be used in JSP.

Amit

The method is public and hence can be accessed by static way.

But still I will try using custom tags for this ...

Any other suggestion is most Welcome.....
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
munish gupta wrote:I think Scriplets can be used in JSP.

They can be. But they shouldn't be. As of about ten years ago.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Matthew Brown wrote:
munish gupta wrote:I think Scriplets can be used in JSP.

They can be. But they shouldn't be. As of about ten years ago.

You can also design a TV using vacuum tubes. But you'd still be using outdated technology.

JSP 2 with the JSTL and EL was introduced in 2002 -- 10 years ago! Don't you think it's time to catch up?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!