Servlet request by java code
1 posts in topic
Flat View  Flat View

Posted By:   Perica_Markovic
Posted On:   Friday, October 10, 2003 08:07 AM


I want to send a request to a servlet by java code.
I have a session bean and I want to send a request by url to a servlet
Could somebody help me?


Perica Markovic

Re: Servlet request by java code

Posted By:   s_kandacharam  
Posted On:   Friday, October 10, 2003 12:19 PM

If you are trying to access servlet from java client program, you should do that using URL objects.On the client side, java program should use the following code to call servlet

String servletGET = "http://perica:80/webApp/MyServlet?param1="+URLEncoder.encode("Give Response");

URL urlServlet = new URL( servletGET );

URLConnection servletConnection = urlServlet.openConnection();

ObjectInputStream inputFromServlet = new ObjectInputStream(servletConnection.getInputStream());

Vector = (Vector) theInputFromServlet.readObject();

On the sevlet side, you can access user request and send the response like the following

public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException

String strUserRequest = request.getParameter("param1");

if(strUserRequest.equals("Give Response")){

Vector vData = myDataAccessor.getDataList();

ObjectOutputStream resOutPut = new ObjectOutputStream(response.getOutputStream());






Hope this helps you.

About | Sitemap | Contact