• 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

Problem with forward and include JSP tag

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Below are two examples where we r trying to pass value to next page but showing error in output.
First Example using include tag
<jsp:include page="two.jsp" flush="true" >
<jsp aram name="name" value="amit" />
</jsp:include>
Here is the file "two.jsp"
<% out.println(request.getParameter("name")); %>
Second Example using forward tag
<jsp:forward page="three.jsp" >
<jsp aram name="name" value="amit" />
</jsp:forward>
Here is the file "three.jsp"
<% out.println(request.getParameter("name")); %>
 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi hasan,
Your program is nicely working and prints "amit" in my computer. I thing there may be some other problem. If you provide me exact error message and from where(dir) you are running this program, I may able to locate the error.
solaiappan
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am confused. My book (core servlets ...) says that you cannot use <jsp:include > in pages that have JSP code inside. However that is exaclty what you are doing.
In "Core Servlets and JSP" page 270 says:
(Speaking about using jsp:include)...On the other hand, the page has already been translated into a servlet by request time, so the including file cannot contain JSP.
Can anyone explain to me why the book says this? Can I include files with JSP content using <jsp:include>?
 
P SOLAIAPPAN
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Humberto ,
I thing you are confused with the above example for explaining
"jsp:include" directive.

<jsp:include page="two.jsp" flush="true" >
<jsp aram name="name" value="amit" />
</jsp:include>
Here is the file "two.jsp"
<% out.println(request.getParameter("name")); %>
You have studied that
" the page has already been translated into a servlet by request time, so the including file cannot contain JSP."
the above statement is a not a completed one some thing is left out.
The general format of "jsp:include" action is
<jsp:include page="local URL" flush="true" >
<jsp aram name="name1"
value="value1" />
.................
<jsp aram name="namen"
value="valuen" />
</jsp:include >
the included page can be a static document, servle or another JSP page.
Even though you can include a JSP page there are restrictions apply, what not to use inside those JSP page for e.g It is not possible to forward to another page, cannot set Cookies or Headers.
But it can use "JspWriter" object
e.g out.println(request.getParameter("name"));
I hope it is clear.
solaiappan
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Could some body please explain me why i am getting null when i tried the above code.
Thanks.
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am also getting null. SOLAIAPPAN could you please explain me why.
Thanks A Lot.
Suja.
 
P SOLAIAPPAN
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I am suspecting that you people might have made some mistake while copying & and pasting because of the "smiling face" appeared above code. Because of that you might have missed the parameter <jsp aram name="name" value="amit" /> check out please.
My code is below:
"one.jsp"
<jsp:include page="two.jsp" flush="true" >
<jsp aram name="name" value="amit" />
</jsp:include>
"two.jsp"
<% out.println(request.getParameter("name")); %>
"forward.jsp"
<jsp:forward page="three.jsp" >
<jsp aram name="name" value="amit" />
</jsp:forward>
"three.jsp"
<% out.println(request.getParameter("name")); %>
run first
"http://localhost:8080/one.jsp"
then
"http://localhost:8080/forward.jsp"
The above is my configuration. change as per yours.
solaiappan

[This message has been edited by P SOLAIAPPAN (edited November 21, 2000).]
 
sujatha mamidala
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Here is my code.
test1.jsp
<jsp:include page="test2.jsp" flush="true" >
<jsp aram name="name" value="amit" />
</jsp:include>
test2.jsp
<% out.println(request.getParameter("name")); %>
when i run the test1.jsp i am getting
"The page cannot be displayed
There is a problem with the page you are trying to reach and it cannot be displayed".
so,i changed the name="name1". Now when i run the test1.jsp again i am getting some parser exception.
Then again i had to change the code in test1.jsp like this
<jsp:include page="test2.jsp" flush="true" />
<jsp aram name="name" value="amit" />
</jsp:include>
Now when i run the test1.jsp again "null is getting printed out.
I would appreciate if you could explain me this strange behaviour.

Thanks A Lot.
Suja.
 
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sujatha,
I have tested the code. Both 'include' and 'forward' work fine. They both print 'amit'.
If I am not wrong , I think your code is missing the ':' (colon) in this 2nd line of 'one.jsp' and 'forward.jsp'.

Now everything will be ok. Try it!. I am using Tomcat3.1 on win98.
regds
maha anna

[This message has been edited by maha anna (edited November 21, 2000).]
 
sujatha mamidala
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Maha,
Thanks for responding. That's exactly how i tried the code.
"jsp aram name="name" value="amit". But it's not working.
Thanks.
Suja.
 
sujatha mamidala
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't know why that smiling face keeps showing up.
<jsp"colon"param name="name" value="amit" />
Maha please explain me what's going wrong here.
Thanks
suja.
 
maha anna
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which servlet container are you using?.
1. First try the include alone. (one.jsp and two.jsp)
2. If you are using Tomcat there will be an 'examples' dir under webapps dir. Copy one.jsp and two.jsp to this dir. Mine looks like this :
C:\jakarta-tomcat\webapps\examples\one.jsp

C:\jakarta-tomcat\webapps\examples\two.jsp

3. Type http://localhost:8080/examples/one.jsp
Tell us what happens?

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