• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Creating a Simple Session Variable

 
Ranch Hand
Posts: 421
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello I have a servlet which serves an xsl page. I wanted to enable that particular servlet to request a session variable.

What I have done to the servlet that serve the xsl page is to put an import: import bcc.pages.parent;

and the code on the parent servlet is as follows:



what is happening now is that the page wont' load.

What I am trying to do is:

1) Create a session variable in your application where you would store the "parentId"
e.g.
request.getSession().setAttribute("parentId",114);

Could you please point me in the right direction?

Thanks,
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
-->servlet often used in multi threading environment. so dont define HttpSession as an instance variable.
-->secondly can you elaborate what problem are you facing?
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But that servlet doesn't output any data, so probably that's why you aren't seeing anything in the response.

And I don't understand what you mean by a "parent" servlet.
 
Michele Smith
Ranch Hand
Posts: 421
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello I am trying to do the following:

(At a high level)

1) Create a session variable in your application where you would store the "parentId"
e.g.
request.getSession().setAttribute("parentId",114);

2) In the report where you are using the parentId to filter the query you will have to read the session variable and add it to the query instead of the report parameter value. However, inorder to make it run from your desktop you may need the parameter otherwise it will always be null.

e.g. in the beforeOpen method of the query

var sessionParentId = null
sessionParentId= reportContext.getHttpServletRequest().getSession().getAttribute("parentId");

if
(sessionParentId== null)

sessionParentId = params[
"parentId"].value;



this.queryText = 'select distinct home_short_name from home where parent_id = ' +sessionParentId;



While calling the report do not pass the parentId in the URL.

-------------------------------------------------------------------------------------------------------------------------------------------------

I understand the beforeopen, I am having trouble with the session servlet described above.

I already have a servlet running the page, the page is displaying some dynamically hyperlinked items in xml 1.0 and because it is dynamically hyperlinked, it displays the parameter parentid on the URL when you click on the hyperlink and it also displays the parameter when you hover above it.

It is already using a bunch of servlets which utilize the following:

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

I don't have a very simple example of creating a session variable, and also I don't know where to put the code for the session variable, i.e., should I put it in with the other servlets:

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

I have been told this session is only necessary on two dynamically hyperlinked landing pages. It would break the whole application if I introduced it globally to the application.

My question to Seetharaman is this:

servlet often used in multi threading environment. so dont define HttpSession as an instance variable.



What should I do if I don't define a httpsession? Thanks,

 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Michele Smith wrote:
My question to Seetharaman is this:

servlet often used in multi threading environment. so dont define HttpSession as an instance variable.



What should I do if I don't define a httpsession?


define inside a service(doGet or doPost) . threads share instance/class variables among them. so person A will get charged, because of B person activities.
 
reply
    Bookmark Topic Watch Topic
  • New Topic