Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to test Servlet using httpunit or junit?Any advice will be helpful.

807603Nov 17 2007 — edited Nov 18 2007
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?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 16 2007
Added on Nov 17 2007
3 comments
470 views