• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How do i get this jsp to work?

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ReadMail.java 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
9
BSD Java
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67746
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
And never mix scriptlets and EL in a JSP -- that's just asking for trouble.
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

reply
    Bookmark Topic Watch Topic
  • New Topic