This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How do i get this jsp to work?  RSS feed

 
Joaquim Amorim
Greenhorn
Posts: 1
  • 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 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
 
Tapas Chand
Ranch Hand
Posts: 614
9
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66188
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • 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.
 
Stefan Evans
Bartender
Posts: 1836
10
  • 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.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!