Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8791957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:54:51+00:00 2026-06-13T22:54:51+00:00

I have written servlet.I want to test the functionality of my servlet class ,so

  • 0

I have written servlet.I want to test the functionality of my servlet class ,so I have written a test case for my servlet.But it throws following exception .

com.meterware.httpunit.HttpException: Error on HTTP request: 405 Method Not Allowed [http://localhost:8090/getPrintSettings]
    at com.meterware.httpunit.WebClient.validateHeaders(WebClient.java:623)
    at com.meterware.httpunit.WebClient.updateClient(WebClient.java:500)
    at com.meterware.httpunit.WebWindow.updateWindow(WebWindow.java:192)
    at com.meterware.httpunit.WebWindow.getSubframeResponse(WebWindow.java:183)
    at com.meterware.httpunit.WebWindow.getResponse(WebWindow.java:158)
    at com.meterware.httpunit.WebClient.getResponse(WebClient.java:122)
    at com.vxoom.qit.basic.GetPrintSettingsTest.testGetForm(GetPrintSettingsTest.java:22)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
    at junit.framework.TestCase.runTest(TestCase.java:154)
    at junit.framework.TestCase.runBare(TestCase.java:127)
    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.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

This is my Servlet class :

public class GetPrintSettings extends HttpServlet {

private Logger log;
DB db;
Connection connection;


public void init() throws ServletException { //initialise servlet
    log = Logger.getRootLogger();
    db = new DB();
    connection = db.connect();
    super.init();
}

public void destroy() {  //destroy servlet
    try {
        connection.close();
    } 
    catch (SQLException e) {
        log.error("AddAddress: SQL Exception: "+e.getMessage());
        e.printStackTrace();
    }
    super.destroy();
}


protected void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {

    int userType = Integer.parseInt(request.getParameter("user"));
    response.setContentType("application/json");        
    PrintWriter out = response.getWriter();

    //Get print settings from JavaClient
    String json = getPrintSettings();

    if(json == null) {
        out.print("{success:false, msg:'Could not send request. Please try again'}");
        out.close();
        return;
    }

    //Send the reply to the web client
    out.print(json);
    out.close();
}

}

This is my servelt testcase

  public class GetPrintSettingsTest extends TestCase {

       public static void main( String args[] ) {

    junit.textui.TestRunner.run(GetPrintSettingsTest.class );
   }

public void testGetForm() throws Exception {
    WebConversation web = new WebConversation();
    WebRequest  request = new GetMethodWebRequest("http://localhost:8090/getPrintSettings" );
    WebResponse response = web.getResponse(request);
    request.setParameter("user", "1");
    response = web.getResponse( request );

}

}

I have used httpunit1.7 please help me …

thanks in advance 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T22:54:52+00:00Added an answer on June 13, 2026 at 10:54 pm

    It is because you have implemented doPost() and accesing GET.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a Java servlet and run it through local Tomcat 7, but
I have written test Filter (javax.servlet.Filter) and started to debug. And I was surprised
The class I have written works fine as a normal Java application, but when
I have written a Servlet something like this public class ServletUtil extends HttpServlet {
I have a servlet/tomcat server written in java. I have a mysql class that
I have written this code inside a servlet to delete certain records from three
I have web application written in java using Eclipse. It has just one servlet
I have this servlet program and an external .jar file (written by someone else)
have written this little class, which generates a UUID every time an object of
I have written a function that sorts a big scale of data. To test

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.