Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

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

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 672
4
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.....
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67634
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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's never done THAT before. Explain it to me tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic