aspose file tools*
The moose likes Servlets and the fly likes Servlet and Jsp Communication Understanding Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet and Jsp Communication Understanding" Watch "Servlet and Jsp Communication Understanding" New topic
Author

Servlet and Jsp Communication Understanding

Romeo Ranjan
Ranch Hand

Joined: Feb 23, 2009
Posts: 92
I am learning how Servlets communicate with JSP.I came across a nice article,here is the link for it http://javapapers.com/servlet/servlet-jsp-communication/.
I am not using any framework for running this sample program.I use JavaEE eclipse for it.Here is the servlet code


Here is the JSP code


This is my web.xml


But what i get when i run this code with http://localhost:8080/ExampleWebProject/
is

Servlet communicated message to JSP: null

Can someone explain me why i get this instead of

Servlet communicated message to JSP: Example source code of Servlet to JSP communication.


SCJP 6.0
Mark E Hansen
Ranch Hand

Joined: Apr 01, 2009
Posts: 642
You set your welcome file to the JSP page. I think you want the welcome file to be the Servlet. The Servlet is then going to set the variables and forward the request on to the JSP page.

By going straight to the JSP page, the Servlet was never called, so how could it set the request attributes?

By the way, one way to prevent this type of error is to place the view JSP pages somewhere under the WEB-INF directory of your web application. The Servlet can still forward to it there, but client browser cannot directly browse to it.

Romeo Ranjan
Ranch Hand

Joined: Feb 23, 2009
Posts: 92
Mark E Hansen wrote:You set your welcome file to the JSP page. I think you want the welcome file to be the Servlet. The Servlet is then going to set the variables and forward the request on to the JSP page.

setting the welcome file to be the servlet worked.

By the way, one way to prevent this type of error is to place the view JSP pages somewhere under the WEB-INF directory of your web application. The Servlet can still forward to it there, but client browser cannot directly browse to it.

Trying out this possibilty: I placed the javaPapers.jsp in the web-inf folder,didn't work it gave the same

Servlet communicated message to JSP: null
Mark E Hansen
Ranch Hand

Joined: Apr 01, 2009
Posts: 642
You're misunderstanding something. With the JSP file under WEB-INF (note: Case is important - it's not web-inf), then the resource cannot be directly accessed by the browser. In other words, you cannot browse to http://localhost:8080/ExampleWebProject/WEB-INF/mypage.jsp, however, your Servlet can forward to the JSP page as "/WEB-INF/mypage.jsp". For example:



 
jQuery in Action, 2nd edition
 
subject: Servlet and Jsp Communication Understanding
 
Similar Threads
Deployement problem
EL Configuration Problem
Prevent intermediate access to any jsp page
Weblogic deployment problem
HTTP Status 405 - HTTP method GET is not supported by this URL