Dear Mostafa,

please find below a test case I just added to show what IMHO is happening.
You might want to register your servlet with the fully qualifying url. If you register "validateLogin" but use "ISB/validateLogin"
you'll get the exception you are seeing (as shown by the JUnit test case below.

You are kindly invited to post your question on with the tag httpunit to let others know about this handling issue.


     * Test added by WF 2012-11-12 to answer question on developers mailing list
     * @throws Exception
    public void testInvalidConfig() throws Exception {
      final String resourceName = "something/interesting";

      ServletRunner sr = new ServletRunner();
      sr.registerServlet(resourceName, ConfigServlet.class.getName());
      WebClient wc = sr.newClient();
      try {
          WebResponse response = wc.getResponse("http://localhost/" + "ISB/"+ resourceName);
          fail("No Exception thrown");
      } catch (Throwable th) {
          // com.meterware.httpunit.HttpNotFoundException:
          // Error on HTTP request: 404 No servlet mapping defined [http://localhost/ISB/something/interesting]
          String expected="Error on HTTP request: 404 No servlet mapping defined [http://localhost/ISB/something/interesting]";
          assertTrue("HttpNotFoundException expected",th instanceof HttpNotFoundException);
          assertEquals("wrong exception message",expected,th.getMessage());

Am 12.11.12 01:38, schrieb mostafa kandil:
Hi httpunit developers team:
first i appreciate the work of httpunit framework, i have 4 weeks ago searching for a tool i can use to test java Servlet. so when i found your framework, i was so happy :D . 
i have downloaded last released, and tried a simple case:
void test(){
     try {
            ServletRunner sr = new ServletRunner();
            sr.registerServlet("validateLogin", "validateLogin");  
                         // or  sr.registerServlet("validateLogin", validateLogin.class.getName());
            ServletUnitClient sc = sr.newClient();
            WebRequest request = new PostMethodWebRequest("");

            request.setParameter("un", "user1");
            request.setParameter("pwd", "userpwd");         
            WebResponse response = sc.getResponse(request);
            assertEquals("requested resource", "user_page.jsp", response.getText());
        } catch (Exception e) {
            System.err.println("ERROR: " + e);
Always i got exception at red line :
  ERROR: com.meterware.httpunit.HttpNotFoundException: Error on HTTP request: 404 No servlet mapping defined []
com.meterware.httpunit.HttpNotFoundException: Error on HTTP request: 404 No servlet mapping defined []
at com.meterware.servletunit.WebApplication$ServletRequestImpl.getServlet(
at com.meterware.servletunit.InvocationContextImpl$ExecutionContext.getServlet(
at com.meterware.servletunit.InvocationContextImpl.getServlet(
at com.meterware.servletunit.InvocationContextImpl.service(
at com.meterware.servletunit.ServletUnitClient.newResponse(
at com.meterware.httpunit.WebClient.createResponse(
at com.meterware.httpunit.WebWindow.getResource(
at com.meterware.httpunit.WebWindow.getSubframeResponse(
at com.meterware.httpunit.WebWindow.getResponse(
at com.meterware.httpunit.WebWindow.getResponse(
at com.meterware.httpunit.WebClient.getResponse(
at myServletTest.testISB(
at myServletTest.<init>(
at myServletTest.main(

i'm using  'Java EE 6 Web', and  netbeans tool.
i have added all libraries.

Can you help me please solve that exception?  

thanks in advance

Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:

Httpunit-develop mailing list


BITPlan - smart solutions
Wolfgang Fahl
Pater-Delp-Str. 1, D-47877 Willich Schiefbahn
Tel. +49 2154 811-480, Fax +49 2154 811-481
BITPlan GmbH, Willich - HRB 6820 Krefeld, Steuer-Nr.: 10258040548, Geschäftsführer: Wolfgang Fahl