I think after much typing and erasing on my part, I finally get what you're wanting... you want two interfaces to a web app. One in the normal fashion, where someone can make requests and receive information. They click links, say for a product brochure. The request might be something like: "http://www.myfoo.com/prods/show?pid=345" which would show us product number 345.
And in addition, you want to enable someone to access this same page of information, by emailing the system like so:
to:
autoresponder@myfoo.com subject: 345
If this is so, then I think there might be a gap in your understanding of web apps and email, and I apologize in advance if I'm not correct.
1) At the moment, when I load the servlet in web browser then only the mails are received. How is a servlet "receiving" email? What's sending it?
Your web app listens on port 80 for http requests. The email is being sent to port 25, and an email server is listening to that port. The email server doesn't even have to be on the same physical machine as your web server.. they have nothing to do with one another.
So you need to bridge the two.
In order for your webapp to 'receive' this email, you need to use JavaMail, and have a background process check a specified mailbox (in our example, the 'autoresponder' inbox) every 'n' seconds for emails. Upon finding an email in the inbox, it needs to retrieve it, parse out the subject (all very easy, through JavaMail) and after that, do its processing and database querying based on the code in the subject.
As for 2)... Again, you use JavaMail. You can have your background process 'reply' to the email it is currently processing, and using various methods of that API, send a plain-text or HTML response to the email.
How to actually "get" the JSP page that normally displays the page when a link is clicked, so that you can place that HTML output into an email? You can use an java.net.HttpUrlConnection to emulate an actual request.