Re: Bean and Servlet
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. 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. On 7/27/07, Pid [EMAIL PROTECTED] wrote: Caldarale, Charles R wrote: From: Mohammed Zabin [mailto:[EMAIL 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@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Bean and Servlet
On 7/27/07, Mohammed Zabin [EMAIL PROTECTED] wrote: 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. 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 [EMAIL PROTECTED] wrote: Caldarale, Charles R wrote: From: Mohammed Zabin [mailto:[EMAIL 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@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Bean and Servlet
Mohammed Zabin wrote: On 7/27/07, Mohammed Zabin [EMAIL PROTECTED] wrote: 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_3an answer/textarea textarea name=question_5another 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 [EMAIL PROTECTED] wrote: Caldarale, Charles R wrote: From: Mohammed Zabin [mailto:[EMAIL 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@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] smime.p7s Description: S/MIME Cryptographic Signature
Re: Bean and Servlet
What do you suggest to overcome this problem? On 7/25/07, Caldarale, Charles R [EMAIL PROTECTED] wrote: From: Mohammed Zabin [mailto:[EMAIL PROTECTED] Subject: Re: Bean and Servlet I will tell you the procedure; At each time the user clickes the first page in the site, a random numbers will be generated and stored in the session. You're missing the point. The user may click multiple times before the first request is even received by the webapp, or the browser may simply fire off multiple parallel requests, or the user may open multiple tabs for the same web site. All of the above will result in multiple concurrent requests occurring for the same session. Does your logic handle that properly? The code snippet you posted does 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@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Bean and Servlet
Caldarale, Charles R wrote: From: Mohammed Zabin [mailto:[EMAIL 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@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] smime.p7s Description: S/MIME Cryptographic Signature
Re: Bean and Servlet
That clarifies a lot :-) ! You are indeed dealing with two separate requests from client to server. As such the Request object won't be the same between the jsp and the servlet and is the reason your storage of an attribute in the request didn't work. Sessions are buit for just this reason. There may be a problem with concurrent access to the session if the user get's click happy or has multiple browser windows open on the same session and you'll have to be able to handle that. In general I would avoid attributes in the session that might cause conflicts depending on where each browser is in the app. In your case two windows could be prompted for a different random question/answer on the same session. Such a issue might be mitigated with a one time random token stored both as a hidden form field and a session attribute. As each request comes in, compare the tokens and handle appropriately. Additionally I believe there was a bugzilla issue describing a version (or versions) of tomcat that didn't use a thread-safe method of storing session attributes, so you might have to introduce synchronize blocks in your code to deal with that. You'll have to look at the bugzilla database for the issue, tomcat version(s) and it's resolution. I don't have that info off hand. --David Mohammed Zabin wrote: Well, I will descript the problem exactly. the first page use a tag class to render a random question from database, and their possible answers, the user must choose the right answer and submit the form for processing. I need the random question numbers, which are question ids to *Results*servlet. *Results* servlet is a servlet that must display the same questions that was displayed in the Questions page to run a query against the database to display the questions and the correct and wrong answers. 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. I tried to use request.setAttribute(Ids, ids); but when retrieve it in Results servlet, I got *null. * That was my problem my buddy, by the way, when i used session, it worked fine. and you stated that this will not work, but i think that storing these ids in a session is a good choice, isn't it? If you have any comments please post it. On 7/26/07, Caldarale, Charles R [EMAIL PROTECTED] wrote: From: Mohammed Zabin [mailto:[EMAIL PROTECTED] Subject: Re: Bean and Servlet What do you suggest to overcome this problem? In the seven messages you've posted in this thread, you've never really explained what this attribute is being used for; nor have you answered the question of whether or not it's used only for the duration of a single request or is applicable to everything a given user does with this particular webapp. Until you give us some idea of what your intent is (as opposed to code snippets), I don't think anyone can really answer your questions. If you do need to store attributes in a session, you will need at least some synchronization logic to see if the attribute is already present, since multiple requests can easily be using the Session object concurrently. - 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@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Bean and Servlet
I have changed like this: pageContext.getRequest().setAttribute(InQry, qry); and retrieve it in the servlet like this: inQry = (String)request.getAttribute(InQry); But when using request attributes, inQry will be null when retrieved? On 7/26/07, Mohammed Zabin [EMAIL PROTECTED] wrote: What do you suggest to overcome this problem? On 7/25/07, Caldarale, Charles R [EMAIL PROTECTED] wrote: From: Mohammed Zabin [mailto:[EMAIL PROTECTED] Subject: Re: Bean and Servlet I will tell you the procedure; At each time the user clickes the first page in the site, a random numbers will be generated and stored in the session. You're missing the point. The user may click multiple times before the first request is even received by the webapp, or the browser may simply fire off multiple parallel requests, or the user may open multiple tabs for the same web site. All of the above will result in multiple concurrent requests occurring for the same session. Does your logic handle that properly? The code snippet you posted does 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@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Bean and Servlet
Well, I will descript the problem exactly. the first page use a tag class to render a random question from database, and their possible answers, the user must choose the right answer and submit the form for processing. I need the random question numbers, which are question ids to *Results*servlet. *Results* servlet is a servlet that must display the same questions that was displayed in the Questions page to run a query against the database to display the questions and the correct and wrong answers. 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. I tried to use request.setAttribute(Ids, ids); but when retrieve it in Results servlet, I got *null. * That was my problem my buddy, by the way, when i used session, it worked fine. and you stated that this will not work, but i think that storing these ids in a session is a good choice, isn't it? If you have any comments please post it. On 7/26/07, Caldarale, Charles R [EMAIL PROTECTED] wrote: From: Mohammed Zabin [mailto:[EMAIL PROTECTED] Subject: Re: Bean and Servlet What do you suggest to overcome this problem? In the seven messages you've posted in this thread, you've never really explained what this attribute is being used for; nor have you answered the question of whether or not it's used only for the duration of a single request or is applicable to everything a given user does with this particular webapp. Until you give us some idea of what your intent is (as opposed to code snippets), I don't think anyone can really answer your questions. If you do need to store attributes in a session, you will need at least some synchronization logic to see if the attribute is already present, since multiple requests can easily be using the Session object concurrently. - 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@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Bean and Servlet
From: Mohammed Zabin [mailto:[EMAIL PROTECTED] Subject: Re: Bean and Servlet What do you suggest to overcome this problem? In the seven messages you've posted in this thread, you've never really explained what this attribute is being used for; nor have you answered the question of whether or not it's used only for the duration of a single request or is applicable to everything a given user does with this particular webapp. Until you give us some idea of what your intent is (as opposed to code snippets), I don't think anyone can really answer your questions. If you do need to store attributes in a session, you will need at least some synchronization logic to see if the attribute is already present, since multiple requests can easily be using the Session object concurrently. - 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@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Bean and Servlet
From: Mohammed Zabin [mailto:[EMAIL PROTECTED] Subject: Re: Bean and Servlet I will tell you the procedure; At each time the user clickes the first page in the site, a random numbers will be generated and stored in the session. You're missing the point. The user may click multiple times before the first request is even received by the webapp, or the browser may simply fire off multiple parallel requests, or the user may open multiple tabs for the same web site. All of the above will result in multiple concurrent requests occurring for the same session. Does your logic handle that properly? The code snippet you posted does 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@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Bean and Servlet
Can you post the relevant parts of how/where you call this servlet? I've never had a problem retrieving a request attribute after it was added and before the end of the request. --David Mohammed Zabin wrote: Actually, I wanted to pass this list from within a Tag to be used inside another Servlet class, (i.e. the tag class after finishing rendering its elements, goes to a servlet, so, i need to pass this list to that servlet. As i have stated above, i used the following to store the list in the request object: [code]pageContext.getRequest().setAttribute(QList, list);[/code] In the servlet, i used the following to retrive the list: ListInteger list = (ListInteger)request.getAttribute( QList); I tried to access the above list by a small code snippet that prints its size: [code]out.println( list.size() );[/code] But i got an exception stating that a NullPointerException has occured at the size printing statement. That's mean, i think, the list didn't stored correctly in the request object, am I true? On 7/23/07, David Smith [EMAIL PROTECTED] wrote: Typical design is servlet forwarding to jsp for view. Tags being jsp elements occur after servlets have executed. So you can see how your problem is a little curious in that jsps don't typically forward to servlets. If you are forwarding a request from jsp to servlet, let us know. However if you are storing a object in a request during jsp execution intending it to be available to the servlet on the next request, that doesn't work. The request is cleared and recycled when jsps finish writing to the client. When a new request comes in, the request attribute list is empty. If you need this list to live between requests, you need to place it in the session. --David Mohammed Zabin wrote: Thank you Johnny, To be specific this is my question Hi all I am trying to pass an object from a tag to a servlet. i did the following, 1. In the tag class, i put: pageContext.getRequest().setAttribute(QList, list); The above Tag will go to a servlet, i need to read the above request attribute in the servlet, how can i do this?, i tried ListInteger list = (ListInteger)request.getAttribute(QList); , but when i tried to access the read list, it gave me NullPointerException...What do u think? On 7/23/07, Johnny Kewl [EMAIL PROTECTED] wrote: Hi Mohammed, Cant say I really understand the question In general this is what the Session Objects are for So say you have a servlet and a JSP page and say the servlet makes the bean with the Array List in it then if you session.setAttribute(MyBean, MyBean); you can get it (MyBean) back when the next call comes into say the JSP page Now if you read up on this you will see you can also set 'request' objects and these are good for when you say dispatch a request to a JSP page from the servlet and want to pass a bean across. Anyway... if you just google for servlet session and setAttribute you will be on your way... I think ;) This area of servlet programming is one of the things that make it such a powerful technology. Have fun... - Original Message - From: Mohammed Zabin [EMAIL PROTECTED] To: Tomcat Users List users@tomcat.apache.org Sent: Monday, July 23, 2007 11:18 AM Subject: Bean and Servlet Hi All What is the best way to pass a list collection from a Bean to a Servlet? Thank you - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Bean and Servlet
Thank you I solve it using session, particularly: pageContext.getSession().setAttribute(InQry, qry); and retreive it in the servlet like this: String inQry = (String)request.getSession().getAttribute(InQry); But, I have a question regarding DBCP, it is not wrong to have more than one CP, isn't it? I mean is it allowed to have a Resource for Oracle and another for MySql? On 7/24/07, David Smith [EMAIL PROTECTED] wrote: Can you post the relevant parts of how/where you call this servlet? I've never had a problem retrieving a request attribute after it was added and before the end of the request. --David Mohammed Zabin wrote: Actually, I wanted to pass this list from within a Tag to be used inside another Servlet class, (i.e. the tag class after finishing rendering its elements, goes to a servlet, so, i need to pass this list to that servlet. As i have stated above, i used the following to store the list in the request object: [code]pageContext.getRequest().setAttribute(QList, list);[/code] In the servlet, i used the following to retrive the list: ListInteger list = (ListInteger)request.getAttribute( QList); I tried to access the above list by a small code snippet that prints its size: [code]out.println( list.size() );[/code] But i got an exception stating that a NullPointerException has occured at the size printing statement. That's mean, i think, the list didn't stored correctly in the request object, am I true? On 7/23/07, David Smith [EMAIL PROTECTED] wrote: Typical design is servlet forwarding to jsp for view. Tags being jsp elements occur after servlets have executed. So you can see how your problem is a little curious in that jsps don't typically forward to servlets. If you are forwarding a request from jsp to servlet, let us know. However if you are storing a object in a request during jsp execution intending it to be available to the servlet on the next request, that doesn't work. The request is cleared and recycled when jsps finish writing to the client. When a new request comes in, the request attribute list is empty. If you need this list to live between requests, you need to place it in the session. --David Mohammed Zabin wrote: Thank you Johnny, To be specific this is my question Hi all I am trying to pass an object from a tag to a servlet. i did the following, 1. In the tag class, i put: pageContext.getRequest().setAttribute(QList, list); The above Tag will go to a servlet, i need to read the above request attribute in the servlet, how can i do this?, i tried ListInteger list = (ListInteger)request.getAttribute(QList); , but when i tried to access the read list, it gave me NullPointerException...What do u think? On 7/23/07, Johnny Kewl [EMAIL PROTECTED] wrote: Hi Mohammed, Cant say I really understand the question In general this is what the Session Objects are for So say you have a servlet and a JSP page and say the servlet makes the bean with the Array List in it then if you session.setAttribute(MyBean, MyBean); you can get it (MyBean) back when the next call comes into say the JSP page Now if you read up on this you will see you can also set 'request' objects and these are good for when you say dispatch a request to a JSP page from the servlet and want to pass a bean across. Anyway... if you just google for servlet session and setAttribute you will be on your way... I think ;) This area of servlet programming is one of the things that make it such a powerful technology. Have fun... - Original Message - From: Mohammed Zabin [EMAIL PROTECTED] To: Tomcat Users List users@tomcat.apache.org Sent: Monday, July 23, 2007 11:18 AM Subject: Bean and Servlet Hi All What is the best way to pass a list collection from a Bean to a Servlet? Thank you - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Bean and Servlet
This should really be in a separate thread, but I don't see any reason multiple resources for a single webapp shouldn't work. BTW, your solution implies the manner you were calling the servlet was in a separate request. If the servlet is called in a separate request, it won't share any of the same request attributes as it's caller. --David Mohammed Zabin wrote: Thank you I solve it using session, particularly: pageContext.getSession().setAttribute(InQry, qry); and retreive it in the servlet like this: String inQry = (String)request.getSession().getAttribute(InQry); But, I have a question regarding DBCP, it is not wrong to have more than one CP, isn't it? I mean is it allowed to have a Resource for Oracle and another for MySql? On 7/24/07, David Smith [EMAIL PROTECTED] wrote: Can you post the relevant parts of how/where you call this servlet? I've never had a problem retrieving a request attribute after it was added and before the end of the request. --David Mohammed Zabin wrote: Actually, I wanted to pass this list from within a Tag to be used inside another Servlet class, (i.e. the tag class after finishing rendering its elements, goes to a servlet, so, i need to pass this list to that servlet. As i have stated above, i used the following to store the list in the request object: [code]pageContext.getRequest().setAttribute(QList, list);[/code] In the servlet, i used the following to retrive the list: ListInteger list = (ListInteger)request.getAttribute( QList); I tried to access the above list by a small code snippet that prints its size: [code]out.println( list.size() );[/code] But i got an exception stating that a NullPointerException has occured at the size printing statement. That's mean, i think, the list didn't stored correctly in the request object, am I true? On 7/23/07, David Smith [EMAIL PROTECTED] wrote: Typical design is servlet forwarding to jsp for view. Tags being jsp elements occur after servlets have executed. So you can see how your problem is a little curious in that jsps don't typically forward to servlets. If you are forwarding a request from jsp to servlet, let us know. However if you are storing a object in a request during jsp execution intending it to be available to the servlet on the next request, that doesn't work. The request is cleared and recycled when jsps finish writing to the client. When a new request comes in, the request attribute list is empty. If you need this list to live between requests, you need to place it in the session. --David Mohammed Zabin wrote: Thank you Johnny, To be specific this is my question Hi all I am trying to pass an object from a tag to a servlet. i did the following, 1. In the tag class, i put: pageContext.getRequest().setAttribute(QList, list); The above Tag will go to a servlet, i need to read the above request attribute in the servlet, how can i do this?, i tried ListInteger list = (ListInteger)request.getAttribute(QList); , but when i tried to access the read list, it gave me NullPointerException...What do u think? On 7/23/07, Johnny Kewl [EMAIL PROTECTED] wrote: Hi Mohammed, Cant say I really understand the question In general this is what the Session Objects are for So say you have a servlet and a JSP page and say the servlet makes the bean with the Array List in it then if you session.setAttribute(MyBean, MyBean); you can get it (MyBean) back when the next call comes into say the JSP page Now if you read up on this you will see you can also set 'request' objects and these are good for when you say dispatch a request to a JSP page from the servlet and want to pass a bean across. Anyway... if you just google for servlet session and setAttribute you will be on your way... I think ;) This area of servlet programming is one of the things that make it such a powerful technology. Have fun... - Original Message - From: Mohammed Zabin [EMAIL PROTECTED] To: Tomcat Users List users@tomcat.apache.org Sent: Monday, July 23, 2007 11:18 AM Subject: Bean and Servlet Hi All What is the best way to pass a list collection from a Bean to a Servlet? Thank you - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail:
RE: Bean and Servlet
From: Mohammed Zabin [mailto:[EMAIL PROTECTED] Subject: Re: Bean and Servlet Thank you I solve it using session, particularly: pageContext.getSession().setAttribute(InQry, qry); Are you sure you want to do that? If multiple requests from the browser are being processed concurrently, any data at session scope will be shared amongst them. - 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@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Bean and Servlet
I will tell you the procedure; At each time the user clickes the first page in the site, a random numbers will be generated and stored in the session. So, i think that each user has its own numbers, right? On 7/24/07, Caldarale, Charles R [EMAIL PROTECTED] wrote: From: Mohammed Zabin [mailto:[EMAIL PROTECTED] Subject: Re: Bean and Servlet Thank you I solve it using session, particularly: pageContext.getSession().setAttribute(InQry, qry); Are you sure you want to do that? If multiple requests from the browser are being processed concurrently, any data at session scope will be shared amongst them. - 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@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Bean and Servlet
Hi Mohammed, Cant say I really understand the question In general this is what the Session Objects are for So say you have a servlet and a JSP page and say the servlet makes the bean with the Array List in it then if you session.setAttribute(MyBean, MyBean); you can get it (MyBean) back when the next call comes into say the JSP page Now if you read up on this you will see you can also set 'request' objects and these are good for when you say dispatch a request to a JSP page from the servlet and want to pass a bean across. Anyway... if you just google for servlet session and setAttribute you will be on your way... I think ;) This area of servlet programming is one of the things that make it such a powerful technology. Have fun... - Original Message - From: Mohammed Zabin [EMAIL PROTECTED] To: Tomcat Users List users@tomcat.apache.org Sent: Monday, July 23, 2007 11:18 AM Subject: Bean and Servlet Hi All What is the best way to pass a list collection from a Bean to a Servlet? Thank you - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Bean and Servlet
Thank you Johnny, To be specific this is my question Hi all I am trying to pass an object from a tag to a servlet. i did the following, 1. In the tag class, i put: pageContext.getRequest().setAttribute(QList, list); The above Tag will go to a servlet, i need to read the above request attribute in the servlet, how can i do this?, i tried ListInteger list = (ListInteger)request.getAttribute(QList); , but when i tried to access the read list, it gave me NullPointerException...What do u think? On 7/23/07, Johnny Kewl [EMAIL PROTECTED] wrote: Hi Mohammed, Cant say I really understand the question In general this is what the Session Objects are for So say you have a servlet and a JSP page and say the servlet makes the bean with the Array List in it then if you session.setAttribute(MyBean, MyBean); you can get it (MyBean) back when the next call comes into say the JSP page Now if you read up on this you will see you can also set 'request' objects and these are good for when you say dispatch a request to a JSP page from the servlet and want to pass a bean across. Anyway... if you just google for servlet session and setAttribute you will be on your way... I think ;) This area of servlet programming is one of the things that make it such a powerful technology. Have fun... - Original Message - From: Mohammed Zabin [EMAIL PROTECTED] To: Tomcat Users List users@tomcat.apache.org Sent: Monday, July 23, 2007 11:18 AM Subject: Bean and Servlet Hi All What is the best way to pass a list collection from a Bean to a Servlet? Thank you - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Bean and Servlet
Typical design is servlet forwarding to jsp for view. Tags being jsp elements occur after servlets have executed. So you can see how your problem is a little curious in that jsps don't typically forward to servlets. If you are forwarding a request from jsp to servlet, let us know. However if you are storing a object in a request during jsp execution intending it to be available to the servlet on the next request, that doesn't work. The request is cleared and recycled when jsps finish writing to the client. When a new request comes in, the request attribute list is empty. If you need this list to live between requests, you need to place it in the session. --David Mohammed Zabin wrote: Thank you Johnny, To be specific this is my question Hi all I am trying to pass an object from a tag to a servlet. i did the following, 1. In the tag class, i put: pageContext.getRequest().setAttribute(QList, list); The above Tag will go to a servlet, i need to read the above request attribute in the servlet, how can i do this?, i tried ListInteger list = (ListInteger)request.getAttribute(QList); , but when i tried to access the read list, it gave me NullPointerException...What do u think? On 7/23/07, Johnny Kewl [EMAIL PROTECTED] wrote: Hi Mohammed, Cant say I really understand the question In general this is what the Session Objects are for So say you have a servlet and a JSP page and say the servlet makes the bean with the Array List in it then if you session.setAttribute(MyBean, MyBean); you can get it (MyBean) back when the next call comes into say the JSP page Now if you read up on this you will see you can also set 'request' objects and these are good for when you say dispatch a request to a JSP page from the servlet and want to pass a bean across. Anyway... if you just google for servlet session and setAttribute you will be on your way... I think ;) This area of servlet programming is one of the things that make it such a powerful technology. Have fun... - Original Message - From: Mohammed Zabin [EMAIL PROTECTED] To: Tomcat Users List users@tomcat.apache.org Sent: Monday, July 23, 2007 11:18 AM Subject: Bean and Servlet Hi All What is the best way to pass a list collection from a Bean to a Servlet? Thank you - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]