I have a servlet that forwards to a presentation jsp page by executing:
req.getRequestDispatcher("/admin/list.jsp").forward(req, resp);
From the FAQ, ServletUnit supports JSPs as long as the jasper libraries are available. I have the jasper libs in the classpath, but when I test my servlet, the redirect to "/admin/list.jsp" throws an HtmlNotFoundException:
com.meterware.httpunit.HttpNotFoundException: Error on HTTP request: 404 /admin/list.jsp
After spending many hours searching the forums and mailing lists, I have found many similar questions with no good answers. The FAQ says this should be possible, and even implies that it is so easy no examples are needed. The best info I could find was a suggestion to register the jsp with ServletRunner:
This is great except I don't know how to get a 'List' class that corresponds to the 'list.jsp' page. I also have not found a way to 'point' ServletUnit at my jsp files. . . where does it look for them, on the classpath?
Thanks for any advice
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I found the solution, and I will share it so that others won't waste a day searching in vain.
I had to modify my ant build script's <junit> tag to point at the location of my JSP files. The 'list.jsp' that could not be found was in the app/admin directory, so I had to use 'app' as the 'dir' attribute of my <junit> tag:
I can also now run the junit test through Eclipse by setting up the 'Run...' dialog correctly. Once I manually set the 'Working Directory' under the 'Arguments' tab to 'app', everything runs great.
Thanks to the servletunit developers, now that I can get it to work servletunit will be an invaluable tool for myself and everyone I work with. If anyone wants to add this setup information to the servletunit documentation/tutorial/FAQ, please do. It may save others a great deal of time.
Thanks again!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I solved the jsp problem by simply placing my jsp in the root of my application.
I am however getting an error when I try to retrieve the servlet response.
The stack trace is as follows:
com.meterware.httpunit.HttpInternalErrorException: Error on HTTP request: 500 javax.servlet.ServletException: org/apache/tools/ant/BuildException [http://localhost/SelectBeer.do]
at com.meterware.servletunit.ServletUnitClient.newResponse(ServletUnitClient.java:115)
at com.meterware.httpunit.WebWindow.getResource(WebWindow.java:164)
at com.meterware.httpunit.WebWindow.getSubframeResponse(WebWindow.java:128)
at com.meterware.httpunit.WebWindow.getResponse(WebWindow.java:121)
at com.meterware.httpunit.WebClient.getResponse(WebClient.java:113)
at com.example.web.BeerSelectTest.setUp(BeerSelectTest.java:65)
at junit.framework.TestCase.runBare(TestCase.java:125)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:421)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:305)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:186)
It seems that the jsp is being found ok, but quite why this error is being produced I do not know, it it possible that I am using the incorrect jars required by Jasper.
(I am using eclipse to run junit and have the following jars in my project:
I have a servlet that forwards to a presentation jsp page by executing:
req.getRequestDispatcher("/admin/list.jsp").forward(req, resp);
From the FAQ, ServletUnit supports JSPs as long as the jasper libraries are available. I have the jasper libs in the classpath, but when I test my servlet, the redirect to "/admin/list.jsp" throws an HtmlNotFoundException:
com.meterware.httpunit.HttpNotFoundException: Error on HTTP request: 404 /admin/list.jsp
After spending many hours searching the forums and mailing lists, I have found many similar questions with no good answers. The FAQ says this should be possible, and even implies that it is so easy no examples are needed. The best info I could find was a suggestion to register the jsp with ServletRunner:
sr.registerServlet("/admin/list.jsp", List.class.getName());
This is great except I don't know how to get a 'List' class that corresponds to the 'list.jsp' page. I also have not found a way to 'point' ServletUnit at my jsp files. . . where does it look for them, on the classpath?
Thanks for any advice
I found the solution, and I will share it so that others won't waste a day searching in vain.
I had to modify my ant build script's <junit> tag to point at the location of my JSP files. The 'list.jsp' that could not be found was in the app/admin directory, so I had to use 'app' as the 'dir' attribute of my <junit> tag:
<junit fork="yes" printsummary="yes" dir="app"> . . . </junit>
I can also now run the junit test through Eclipse by setting up the 'Run...' dialog correctly. Once I manually set the 'Working Directory' under the 'Arguments' tab to 'app', everything runs great.
Thanks to the servletunit developers, now that I can get it to work servletunit will be an invaluable tool for myself and everyone I work with. If anyone wants to add this setup information to the servletunit documentation/tutorial/FAQ, please do. It may save others a great deal of time.
Thanks again!
I am attempting to do a very similar thing.
I solved the jsp problem by simply placing my jsp in the root of my application.
I am however getting an error when I try to retrieve the servlet response.
The stack trace is as follows:
com.meterware.httpunit.HttpInternalErrorException: Error on HTTP request: 500 javax.servlet.ServletException: org/apache/tools/ant/BuildException [http://localhost/SelectBeer.do]
at com.meterware.servletunit.ServletUnitClient.newResponse(ServletUnitClient.java:115)
at com.meterware.httpunit.WebWindow.getResource(WebWindow.java:164)
at com.meterware.httpunit.WebWindow.getSubframeResponse(WebWindow.java:128)
at com.meterware.httpunit.WebWindow.getResponse(WebWindow.java:121)
at com.meterware.httpunit.WebClient.getResponse(WebClient.java:113)
at com.example.web.BeerSelectTest.setUp(BeerSelectTest.java:65)
at junit.framework.TestCase.runBare(TestCase.java:125)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:421)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:305)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:186)
It seems that the jsp is being found ok, but quite why this error is being produced I do not know, it it possible that I am using the incorrect jars required by Jasper.
(I am using eclipse to run junit and have the following jars in my project:
commons-logging-api.jar
httpunit.jar
jasper-compiler.jar
jasper-runtime.jar
jsp-api.jar
junit.jar
nekohtml.jar
Tidy.jar
xercesImpl.jar
xmlParserAPIs.jar
Any help would be much appreciated.
regards,
Aldred