----- Original Message -----
From: "Rakesh Bhalla" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>; "Vincent Massol" <[EMAIL PROTECTED]>
Sent: Thursday, September 20, 2001 2:42 PM
Subject: Any Error in redirection of JSP ????


> Hello,
>
> --- Vincent Massol <[EMAIL PROTECTED]> wrote:
>   I made the changes as you mentioned. The revised Java code looks
> something like this.
>
> <-- JAVA SRC -- >
>
> import java.util.*;
> import java.text.*;
> import javax.servlet.*;
> import javax.servlet.http.*;
> import java.net.*;
> import java.io.*;
>
> import junit.framework.*;
>
> import org.apache.commons.cactus.*;
>
> public class TestJspTestCase extends JspTestCase
> {
>   static final String FORWARD_URL = "/hello.jsp" ;
>
>     public TestJspTestCase(String theName)
>     {
>         super(theName);
>     }
>
>     public static void main(String[] theArgs)
>     {
>         junit.ui.TestRunner.main(
> new String[] {TestJspTestCase.class.getName()});
>     }
>
>     public static Test suite()
>     {
>         return new TestSuite(TestJspTestCase.class);
>     }
>
>
>     public void testOut() throws IOException, ServletException
>     {
> pageContext.forward(FORWARD_URL);
> assertEquals("LG" , session.getAttribute("name") );
>     }
> }
>
>  -->
>
> The JSP code looks like this
>
> <--JSP code
> <!doctype html public "-//w3c/dtd HTML 4.0//en">
> <html>
> <head><title>Hello World</title></head>
> <body>
> <% session.setAttribute("name" , "RED" ); %>
> <% out.print("Hello Your Universe!"); %>
> </body>
> </html>
>
>  <--  JSP Code -->
>
> Actually this is present  in the WebServer such that it can be
> referred to as:
>
> http://localhost:7001/examplesWebApp/hello.jsp .
>
> Now when I run JUnit I get the AssertionFailedError but it says,
>
> junit.framework.AssertionFailedError: expected:<LG> but was:<null>
>
> Actually the other value should have been RED .
>
> So the session attribute is not set at all. Have I gone wrong in
> forwarding the PageContext ?

You must be careful that the jsp you forward to is actually located at the
correct place because it the JSP engine is not able to find the JSP no
exception will be raised. Instead, the web server will call its default 404
not found page (you can check that by writing "assertEquals("anything",
theResponse.getText());" in the endXXX() method - that's using the new
syntax -use the AssertUtils.getResponseAsString() for the old syntax).

As you have "/hello.jsp", it means the JSP page needs to be located just
under your context directory (i.e. examplesWebApp).

I suspect your JSP page is not called, which is why nothing is written in
the session.
-Vincent

FYI, I have tried your sample on my machine and it works fine.


Reply via email to