Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » Apache Tomcat »

Re: Bean and Servlet

Pid

2007-07-27

Replies:

Mohammed Zabin wrote:
> On 7/27/07, Mohammed Zabin <jotnarta@(protected):
>> Ok, in the first page, which use a tag, I generate 10 random numbers. and
>> generate a SQL statement containing this numbers like the following:
>> SELECT * FROM table WHERE id in ( 2, 3, 5, 10, .... etc). I use a string
>> to hold the " in " statement and bound it to the whole query string.
>>
>> After submitting the page, I need to check the validety of the answers,
>> for the same questions. So, I store the inStr in a session and read it in
>> the second page.

why not just include the question id in the fieldname and submit with
the answer?

<textarea name="question_3">an answer</textarea>
<textarea name="question_5">another answer</textarea>


Enumeration paramNames = request.getParameterNames();
while (paramNames.hasMoreElements()) {
 String name = (String) paramNames.nextElement();
 if (name.startsWith("question_")) {
   String id = name.replaceFirst("question_", "");

   // or remove 'all not digits'
   // String numeric_id = name.replaceAll("\\D", "");

   String value = request.getParameter(name);

   // id=3, value=an answer
   // id=5, value=another answer
 }
}


>> Regarding concurrency issue, I think that I don't need to synchronize
>> random number generation. Because I don't have a problem for multiple
>> requests to have the same set of questions. The most important issue is that
>> for a given request, I need to submit the same collection of questions
>> to Results page. And so, i used session to store the questions ids'.
>>
>>
>> On 7/27/07, Pid <p@(protected):
>>> Caldarale, Charles R wrote:
>>>>> From: Mohammed Zabin [mailto:jotnarta@(protected) ]
>>>>> Subject: Re: Bean and Servlet
>>>>>
>>>>> My Problem is that, I want to pass these numbers, Questions
>>>>> IDs, from the first page, which i have made it as a tag class,
>>>>> to Results page, which was made as servlet.
>>>> Rather than hanging onto the ID within Tomcat, why not store it on the
>>>> generated web page (as a hidden field) and have some script on that
>>> page
>>>> include it with the next request from the client? That way you avoid
>>>> all synchronization issues that can occur with simultaneous requests.
>>> It sounds like a simple form submit with (a) hidden field(s).
>>>
>>> Why do all of the rest of the ids need to be submitted as well, if
>>> you're only checking for the single correct answer?
>>>
>>> p
>>>
>>>
>>>>> That was my problem my buddy, by the way, when i used
>>>>> session, it worked fine. and you stated that this will
>>>>> not work
>>>> I didn't say it wouldn't work, I said you had to be careful and take
>>>> concurrency into account, which your code snippets did not.
>>>>
>>>> - Chuck
>>>>
>>>>
>>>> THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE
>>> PROPRIETARY
>>>> MATERIAL and is thus for use only by the intended recipient. If you
>>>> received this in error, please contact the sender and delete the
>>> e-mail
>>>> and its attachments from all computers.
>>>>
>>>> ---------------------------------------------------------------------
>>>> To start a new topic, e-mail: users@(protected)
>>>> To unsubscribe, e-mail: users-unsubscribe@(protected)
>>>> For additional commands, e-mail: users-help@(protected)
>>>>
>>>>
>>>
>>>
>


Attachment: smime.p7s
©2008 junlu.com - Jax Systems, LLC, U.S.A.