Reading parameters in Servlet passed in from Client

Discussions

Web tier: servlets, JSP, Web frameworks: Reading parameters in Servlet passed in from Client

  1. Hi;
    I have a question regarding passage of parameters from the command prompt to my servlet which reads in HTTP parameters.I am reading in the parameters from a client program and then calling the servlet(from the command prompt using URL class).The servlet inturn takes in the paramaters,does the database work and gives out the result in the console.The servlet works pretty well if I hard code the servlet parameters in the servlet itself,but my question here is:-
    How to read the parameters passed from the client program in the servlet code?Is there any way I got retrieve those parameters. Details:-
    My client(client program):-Command prompt(MS DOS) My server(servlet):-Visual Age 3.5(Web Sphere Test Environment) Thanking You
    Ashwin

  2. Hi,
    Okay I have been now successfully been able to read the parameters given from a client program invoked on the command prompt in a servlet and give out the result in the console.I can do that by using a URL class and invoking the servlet in this way from the client program:-
    URL url = new URL("http://localhost:8080/servlet/MyServlet?param1=A&param2=B&param3=C");
    In servlet code I use(to read those parameters):-
    String param1 = new String();
    param1 = req.getParameter("param1");
    ..
    ***Now the Problem is :-***
    I am able to run the program successfly the first time but if I run the program a second time or change the parameters in the client(recompile & then run),I don't get the result.Only if I stop & then re-start my servlet engine(which is on the server side),I am able to run this correctly.
    Can any please let me know what is the problem?
    Thanking you,
    Ashwin
  3. when u refer to a servlet the first time its init method gets called and subsequently doget, other times only doget is called. so according to me i suppose u r doing some stuff in init which should ideally be in the doget method. check the servlet code, maybe u can find something out there. this is really a long shot in the dark given the information u have provided. sorry if i guessed wrong. bye.