Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SERVLET INPUT

Status
Not open for further replies.

Smarty

Programmer
Apr 12, 2001
191
BE
Is it possible to recieve input within a servlet, and if yes... how? I'm running a servlet, but in the middle of my servlet, i need input from the client. How do i manage this problem?
WHAT I DON'T NEED is connection through the URL with parameters, because my servlet is already running...

Thanx
 
Hi,

I doubt it is possible to get any inputs from the client while the servlet is processing.

Depending on your situation and if possible, you can try to get the client to enter all necessary inputs before calling your servlet.

Another way is to create another servlet to process the second time inputs. Meaning after your first servlet is called, it will display out necessary information and then the client would be required to enter input for the second time and this would call the second servlet.

The last method, which is the one I would use, is the same as the previous method except that instead of creating another servlet to handle the second input, you can embed into your html codes
<input type=&quot;hidden&quot; name=&quot;formName&quot; value=&quot;firstInput&quot;>
for the first html and
<input type=&quot;hidden&quot; name=&quot;formName&quot; value=&quot;secondInput&quot;>
for the second html (which is the output from the first input by the servlet)

Within your servlets use the method
request.getParameter(&quot;formName&quot;); <- this would return a string. request is an instance of HttpServletRequest.

Check the string with &quot;firstInput&quot; and &quot;secondInput&quot; and this would process the client's input accordingly. So it would be like the first time the client connects to your servlet, it would have <input type=&quot;hidden&quot; name=&quot;formName&quot; value=&quot;firstInput&quot;> embeded into the html codes.

Your servlet will get the &quot;formName&quot; from the html codes with the value of &quot;firstInput&quot;. It will then process this first input and will display the output (which can display the processed information if you want and will call the client to enter the input for the second processing). This dynamically created html would have the tag <input type=&quot;hidden&quot; name=&quot;formName&quot; value=&quot;secondInput&quot;> embeded into it.

It will then call the SAME servlet again and the servlet would get the &quot;formName&quot; as &quot;secondInput&quot; and will then process accordingly.

Regards,
Leon If you need additional help, you can email to me at zaoliang@hotmail.com I don't guaranty that I will be able to solve your problems but I will try my best :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top