Help!!!How to test Servlet?

how to test servlet with the code below.
in method doPost or doGet,
doPost(HttpServletRequest req,HttpServletResponse resp)
DataInputStream dis =null;
String data="";
dis = new DataInputStream(req.getInputStream());
data=dis.readUTF();// readInt(),readBoolean() ,etc may applied
System.out.println("data:"+data);
if i code req.getParameter("param"); then i wrote test programm like this request.setParameter("param","something");the servlet can get the value.
my question is ,how can i test the code above?how to set the input value so that the HttpServletRequest object can read the data?

1) Do yoiu mean how to "run" your servlet code with sample parameter? This call manual testing with a sample run of you code. You need a web server(eg Tomcat), create a webapp with your servlet then deploy it there in order to run it.
2) httpunit and junit are framework to write test case code that can be automated and repeatable. Plz read their doc.
3) Your sample code me a very wrong way to retrieve and convert servlet parameters.
Get a java toturial and servlet tutorial book and read it over the weekend. You need to get at least the basic.

Similar Messages

  • How to test servlet using Junit test????

    Hello everybody
    Does anybody know how to test an servlet class using Junit without using Cactus test . Is it possible to test a servlet using Junit without cactus test.Plz tell me the process how to test a servlet using Junit test .
    Regards
    srikant

    1) Do yoiu mean how to "run" your servlet code with sample parameter? This call manual testing with a sample run of you code. You need a web server(eg Tomcat), create a webapp with your servlet then deploy it there in order to run it.
    2) httpunit and junit are framework to write test case code that can be automated and repeatable. Plz read their doc.
    3) Your sample code me a very wrong way to retrieve and convert servlet parameters.
    Get a java toturial and servlet tutorial book and read it over the weekend. You need to get at least the basic.

  • Help : How to test interface mapping in n:1 scenario

    I have a scenario two message interfaces==> one message interface.
    Then I new one interface mapping, and choose two source interfaces, one target interface. Also filled the mapping program.
    But when switch to the test tab, there is no display about the source and target message.
    How to do the test in this kind of scenario?
    Thanks a lot!
    Edited by: kiki qin on Oct 28, 2008 2:24 PM

    Hi
    First check in Message mapping first if you have one.
    Secondly when you select source or target message while developing message mapping did u get message like No objects found or something.
    It should show either error or source message when you test interface mapping in any case.
    Thanks
    Gaurav

  • How to test Adapter Module

    Hi
    My Scenario is File - to - File
    I have written one adapter module and i have deployed in J2ee Engine as well. In sender communication channel i have given the JNDI name like
    <b>"localejbs/<JNDI Name>"</b>.I have tested the my file to file scenario by placing a file in source directory which i have mentioned in Communication channel Source Directory and File Name.But i didnt find any difference in target file.
    I have used the following blog
    <b>
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/da5675d1-0301-0010-9584-f6cb18c04805</b>
    1.How to test the adapter module.
    2.How to configure my communication channel.
    Please help me its very urgent
    Best Regards
    Ravi Shankar B

    Hi,
    check JNDI service in visual admin to see if
    your service has the same name there
    >>>>1.How to test the adapter module.
    by using it in a channel
    >>>>2.How to configure my communication channel.
    add you adapter module to the adapter module tab
    in communication channel
    Regards,
    michal

  • HOw to test the jms connection?

    HI all,
    how to test the jms connection in xi?
    regards
    kish

    HI,
    We can see the JMS sender or reciver side .. in RWB .. see  communicaiton channel mononitoring,., also..
    We can access it through browser.. it depends upon the proocol type .. like sonic or webspeare MQ..or ...
    see below links
    http://help.sap.com/saphelp_nw04/helpdata/en/cf/886a3c3a860657e10000000a114084/frameset.htm
    /people/alessandro.guarneri/blog/2006/01/04/jms-sender-adapter-handling-too-short-lines
    /people/william.li/blog/2006/11/13/how-to-use-saps-webas-j2ees-jms-queue-in-exchange-infrastructure
    content conversion https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/f02d12a7-0201-0010-5780-8bfc7d12f891
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/97171dd3-0401-0010-5195-b43f556e6ce9
    Chilla

  • How to test whether XI is sending file or not?

    Hi all!
    My scenario is like this:File(File sender Adapter)->XI->(HTTP receiver adapter)J2EE appl.
    I placed the xml file in D:\somedir on my PC. It is picking up the file, after picking it should post the same xml file to my j2ee appl. My servlet receives the xml file and display it on browser. But nothing is displayed. How to test whether XI is sending XML file to J2EE appl or not? All helpful answers are highly appreciated.
    Thanks!

    Hi
    In the file adapter i set processing mode as delete, it is picking up well from my d:\somedir.
    I got success flag in SXMB_MONI and successful status in RWB->message monitoring?
    Why my servlet is not able to display?
    All helpful answers are rewarded.
    public class DisplayRes extends HttpServlet {
         public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
                        doPost(request,response);
         public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
         BufferedReader brin =new BufferedReader(new InputStreamReader(request.getInputStream()));
         String inputLine;
         StringBuffer sBuf = new StringBuffer();
         while ((inputLine = brin.readLine()) != null)
             sBuf.append(inputLine);
             brin.close();
             PrintWriter out = response.getWriter();
             response.setContentType("text/xml");
             //out.setContentType("text/xml");
             //out.println(sBuf.toString());
             out.write(sBuf.toString());
             out.flush();
    Thanks

  • How can send servlet out put to jsp

    Hi friends,
    my problem is ..
    1.In my jsp (let us assume that Test.jsp ) emded tag which emding out put from Servlet.. like
    <embed name="svg" border="1" type="image/svg+xml" width="100%" height="100%" src="http://localhost:8080/demo/Test?"/>
    here the jsp is calling Servlets but at the time display the jsp cannot understand the out put comming from servlets ..
    plz help how can read a Servlet data from JSP
    thanks

    Use <jsp:include page="relative_url_to_servlet"/>. Then have your servlet get the PrintWriter for output from response.getWriter() and you should have it.
    I do this every once in awhile.

  • Do not know how to call Servlet from a JSP???

    How do I call a Servlet from a JSP page?
    I have an JSP page that does a few things but when there is an error I need the JSP page to call a Servlet but do not know how to do it.
    I want to call a ServletFaillogin from a JSP page how can I do it?
    <html><head>
    <title> Login Page </title>
    </head>
    <body>
    <%@ page import= "portal.* " %>
    <jsp:useBean class="portal.PortalSystem" id="bean" scope="session" />
    <% try
      String servername = request.getParameter("servername");
      String username = request.getParameter("username");
      String password = request.getParameter("password");
      bean.Connect(servername, username, password);
    catch(Exception e)
       //******Here I need help *********
       action="http://localhost:8080/test/servlet/ServletFaillogin";
    %>
    <h1> You have successfully logged in. </h1>
    </body></html>

    I have changed the code but get error, why??
    I think it could be due to the way classes are located,
    All my HTML and JSP pages are at:
    C:\tomcat\jakarta-tomcat-3.3.1\webapps\myJSPs\jsp\portal-project
    The class ServletFaillogin is located here:
    C:\tomcat\jakarta-tomcat-3.3.1\webapps\myJSPs\WEB-INF\classes\portal
    What am I doing wrong, please help???
    <html><head> <title> FTP Login </title> </head>
    <body>
    <%@ page import= "portal.* " %>
    <jsp:useBean class="portal.PortalSystem" id="bean" scope="session" />
    <%      try
               String servername = request.getParameter("servername");
               String username   = request.getParameter("username");   
               String password   = request.getParameter("password");
               bean.Connect(servername, username, password);
            catch(Exception e)
               response.sendRedirect("http://localhost:8080/myJSPs/servlet/ServletFaillogin");
    %>
    <h1> You have successfully logged in. </h1>
    </body></html>

  • How to test J2EE apps?

    deploying is ok but don't know how to test my servlet?
    what is URL?
    and how J2EE application server manage servlet in "action" attribute of
    HTML form?

    Wow man!!
    The url of your app is set by the context root tag, if you are using S1AS, on the sun-web.xml deployment descriptor. You can see what it is throught deploytool also.
    The servlets URL is given by the servlet-mapping tag in the web deployment descriptor (web), for example:
    <servlet>
    <servlet-name>Foo</servlet-name>
    <servlet-class>org.demo.Foobar</servlet-class>
    <servlet>
    <servlet-mapping>
    <servlet-name>Foo</servlet-name>
    <url-pattern>/Foobar</url-pattern>
    </servlet-mapping>
    Will map the URL for the Foobar servlet at:
    http://yourhost/[context-root]/Foobar
    Hope it helps,
    May the code be with you.

  • How to test the migrated workflows in SharePoint 2013

    Hi, we are migrated the portal from SharePoint (Moss) 2007 to SharePoint 2013 using Doc Ave tool.
    Now my concern is how to test all (OOTB and SharePoint Designer) workflows are working properly in SharePoint 2013.
    How to approach? Any ideas/help will be appreciated.

    Hi Ashok,
    Have the business users that use them or the folks that created them test them in the DEV environment prior to the PRD migration...
    -Ivan

  • How to test domain controller on upgraded Win Server 2008 R2

    The windows team recently upgraded the development environment for the domain controller from 2003 to Windows 2008 R2 and I am to test the Idm functionality on this upgraded version. Our current configuration is that the DC and Idm gateway runs on different machines. To test this new DC, i want to install the idm gateway on that server and run some onboarding and termination test cases just to make sure if the AD connection is working on the upgraded DC. But i am getting ’Input/output error’ when i try to install the service and from the documentation it says 'The most common cause of this is that you do not have rights to work with this service.'. The server admin tried installing the gateway with his id as well and it failed. He tested installing in on the 2003 version of DC and it worked, so its not a matter of permission (i think..)...
    Does anyone have any better idea on how to test an upgrade of a DC from version 2003 to 2008 R2? Any help in this matter is appreciated. We are running Idm 8.1 on a Windows platform and an upgrade to OW 8.1.1. Patch 2 is also in the works..
    Thanks in advance.

    I may have found a workaround. Can you try to change the "compatibility mode" in 2008 R2 to "Windows XP SP3" and see if it will install?
    Admittedly I have not done this myself so I'm not entirely sure where or how it's done, but I have confirmation it resolves the issue from others who have faced it.

  • How to test the interfaces in XI ?

    Hi ,
    Our Xi system is being upgraded from 3.0 to 7.0. I was asked to test the interfaces once the upgradation is done. I am not sure how this testing is to be done and will there be aby test plan for this??
    Can some one help me on this ??
    Thanks in Advance,
    Hemanthika

    To test, you must have imported all your scenarios in to your new system.then couple of general tips,
    1.testing can be done only after understanding the scenario.
    For this, u refer to the integration scenario in ur design. so this shall give u an idea about all the systems involved in integration and how the data flowing is between them and what kind of systems they are?
    2. For testdata, you might need of business or functional team as you cannot have any info on the file formats etc(depending on different scenarios invloved like R3, SOAP Databse etc)
    these are only general tips. but u can refer to many of the trouble shooting guides already available blogs in sdn for any sought of inputs.But then, SDN is always there.
    you can test/monitor ur results in RWB->component monitoring
    also in sxmb_moni
    thanks
    kiran
    Edited by: kiran dasari on Mar 17, 2008 4:44 PM

  • HOW TO TEST SOAP SENDER TO FILE SCENARIO

    Hi gurus,
    I have designed and configured SOAP to file scenario.
    I have used http://xyz namespace in design time.
    I have created two business systems for this sceanrio.
    I have downloaded and installed soap client on my system.
    When I open this soap client it is asking
    1)URL
    2)load request from
    3)In the editor request tab what should i give.
    4)wht is the response tab here
    I want to send data to XI from SOAP and then to file.
    Please help how to give data and how to get the data format to give in the requst editor?
    Points will B rewarded
    Regards
    Sreeni

    Hi,
    You can use a SOAP client like Altova XML spy for posting a message to XI.
    The best way to do this is to use the generated wsdl for creating a soap request.
    once the wsdl file is picked up by the soap client, it automatically generates the url.
    now the response which comes back to the soap client is usually a http status code of successful post. (since u r performing an async scenario)
    also ensure u use the j2ee port while genrating the wsdl using the "Create Webservice" option in Int Directory.
    Also chk the link for the weblog on sender soap scenario.
    /people/siva.maranani/blog/2005/03/01/testing-xi-exposed-web-services
    Hope this helps.
    Award points if found helpful
    Cheers!!
    Sidharth

  • How to Test, Inbound idoc ,with out the Sender System, using a Text File

    Hi Guru's .
    we wanted to test BLAORD03 inbound idoc (Message Type BLAORD).with out the SENDER SYSTEM.
    on the same client.
    we wanted to test this idoc with text file from our local machine.
    Can anyone give us detail steps.like how to create  File layout
    with Segment name,and values for the fields.how to pass this file to the system.
    Thanks in advance.

    Hi Aparna.
    My requirement is to test the idoc with Inbound File.
    Generate a file with the data entered through segments through we19 ,and use the same file for processing through we16.
    when i am trying to do this syst complaing about
    Partner Profile not available, and some times
    port not available. and some  times with
    'No further processing defined'.
    but i maintained part profiles and port perfectly.
    Can you help me in testing with test 'File' port.

  • How to test BLOB Table Column in BCBrowser??

    Hi,
    My requirement is to upload a file(pdf,doc,jpg, txt) into DB using ADF.
    I use, Jdev 11.1.1.6, Oracle 10g XE.
    For this, I created the following
    1. A table as MyFilesTab(ID Number, FileName Varchar2(80), File BLOB)
    2. An Entity Object MyFilesEO on MyFilesTab.
    3. Generated a default view object: MyFilesVO
    4. Application Module : TestAM with view instance "MyFiles"
    But When I run TestAM, I see MyFiles as an Input textbox. So I cannot able to add a file that will be stored in my Table.
    Please help me out.

    Just to clarify, my previous post is related to title of this thread("How to test BLOB Table Column in BCBrowser??"),
    and not to "My requirement is to upload a file(pdf,doc,jpg, txt) into DB using ADF" 
    Dario

Maybe you are looking for

  • Verify whether the session data is kept in the Coherence caches

    I have successfully combined the MapViewer application with WebLogic and Oracle Coherence*Web. How to verify whether the session data of MapViewer application is kept in the Coherence caches or not? All out put show that both of MapViewer and WebLogi

  • How to use multipe songs with a slideshow ?

    Yesterday suddenly some clients came over to see my work. Besides showing them the albums i thought it would be cool to also to show them a slideshow. I knew lightroom could do this, so i quickly selected a bunch of foto's and went to the slideshow m

  • Do we have any tools to embed OC4J to partner's application?

    Do we have any tools to embed OC4J to partner's application? Just like the way we use embedded oc4j in JDeveloper.

  • Where can I find the description of the codes returned by exitValue()?

    Hi Everybody, I have a java porgram on HP/UX and this program executes the OS level commands and exe file on HP UNIX. When I supply "/usr/bin ls -l" as a param to this program it executes it very well. But if I pass the "/utils/Myapp/app arg1 arg2" a

  • Cirrus limitations we must know

    Hello people, we are using the Cirrus  service as a rendezvous point, not with RTMFP groups, to establish peer  to peer connections based on RTMFP, i.e. one to one conversations. We have built a  service around this and we wish to know about some det