Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

How do i get this jsp to work?

Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello friends,

I'm trying to get this jsp to work but i'm not getting lucky.

What it does? Basically it reads new email entries from my gmail account.

I want them to appear in a HTML page recurring to a JSP.

The code is as follows:

Java class:

And the JSP:

Everything seems to be well configured (Tomcat, environment variables, libraries, classes, etc). No errors on output at all.

And when i run the application on NetBeans (as as app), it runs correctly and returns the correct entries from my INBOX folder. So everything should be working.

The problem is i don't know for certain how to write that java class in a JSP.

Can you guys please give me a help?

Thank you in advance.

J Amorim
Ranch Hand
Posts: 624
BSD Java
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java method should not be called from JSP.
Call the method from a Servlet, store the values in POJO.
Pass the details to JSP and display them.
Posts: 67418
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And never mix scriptlets and EL in a JSP -- that's just asking for trouble.
Posts: 1845
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The ReadMail class has been written to connect to the email service , read the messages from the server and write the messages in text to System.out.
It does all of this in one call to its constructor.
That isn't going to be useful to you in a web application.

I think you need to refactor your ReadMail class.  
At a minimum you need to split out the "creation of the object", "reading of messages" and the "printing of messages" into seperate operations so that you can invoke it something like:

Once you have done that then your JSP should be able to construct a ReadMail object, and call the readMessages() method.
You then add logic to the JSP to display those messages appropriately.
Note that the JSP should probably NOT use the ReadMail class to print out the messages.   That is what JSPs are for - displaying java objects.

With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic