steve Barf

Greenhorn
+ Follow
since Oct 15, 2004
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by steve Barf

ok 2 things :

(1) I realise I didn't got the manager properly in the BeanManagersStaff constructor, fixed below.
The question is still the same - why is the request scope BeanManagersStaff created in the Render_Response(6) phase ? Is there a better way ?



(2) The user id is also used as the password hence the database call :

18 years ago
JSF
I have a userDetails screen based on a managed session scope UserBean. I have created a simple outputLink on the Manager Id label to go to a managerPlusStaff screen :



The managerPlusStaff.jsp is based on a managed request scope BeanManagersStaff bean. The constructor for BeanManagersStaff populates the bean properties (manager+staff) by accessing the session scope UserBean to get the Manager Id.

This all works fine and I can see from a trace that the BeanManagersStaff is created in the Render_Response(6) step. BUT WHY AND IS THIS THE BEST WAY.

BeanManagersStaff below:

18 years ago
JSF
Or 25 <navigation-case>s ...
18 years ago
JSF
Don't know much about JSF yet - being 'urged' to use it by customer. But if one of the benefits is that the 'controller' part of mvc is exposed in the faces-config.xml file - how would one handle navigation from a menu eg. a jscookmenu where you can navigate to say 25 different destinations ? Surely you wouldn't have 25 navigation-rules for each screen ?

18 years ago
JSF
We specifically aimed for JSP's with an absolute minimum of code. This is because I inherited an applicaion with >1000 line JSP's which I swore I would never duplicate.

Each request from a given JSP first went to a corresponding servlet. Processing was performed by the servlet and a javabean with request scope. Shared data was held in session and application beans. The final response was generated by the JSP retrieving stored data in the session(s)/application(a) bean plus derived data in the request(r) scope javabean. ie. the jsp handeled the displaying and not the processing.

Along Model 2 lines.
This'll probably make you all laugh but who cares, in a recent jsp/servlet/bean program I wrote with someone new to java who couldn't keep track of the scope of different variables I ended up prefixing the variables as follows :
application - a
session - s
request - r
instance - i
local - l
and arguments/parameters into methods with 'parm'.

I had to check a piece of the code today not having looked at it since before Christmas and found it very useful.

Go on then laugh.
Ben,
Thanks, that book seems better than others I have read on servlets/jsps.
But I didn't see anything on 'context listeners' - if this is not the same as the ServletContext then this is new to me. Searches on google have resulted in articles relating to EJB's or products that use it, rather than using it in the raw. Could you supply some more guidance please ?

My other option is to use the ServletContext as first mentioned :



but to do it in a servlet that runs on server startup.

Steve
19 years ago
Ben,
Thanks for your quick reply. I'd be grateful for your comments on my understanding of your points.
  • 1) a) Could there be a problem that the bean is GCed between creation by the servlet and given application scope in the jsp ?

  • b) Does the application scope implicitly generate a reference which will therefore prevent GC ?
  • 2) Could you expand on this please or point me to a simple reference.
  • 3) Maybe I could do both. I would like to have a go at a singleton, does the following look suitable :



  • There is another singleton method I've seen but I can't see how the getInstance() method would fit in with serrvlets/jsps



    Steve
    19 years ago
    I am thinking of writing a bean to hold a quantity of database information to prevent every user of a web application having to retrieve all the data.



    But I have a few concerns :
  • 1) what would stop this bean from being garbage collected ?
  • 2) what would be the best way to create the bean ?


  • something like this ? :

    and then reference it in jsp's by :

  • 3) should the bean be created as a singleton ?


  • Steve
    19 years ago
    I am thinking of writing a bean to hold a quantity of database information to prevent every user of a web application having to retrieve all the data.



    But I have a few concerns :
  • 1) what would stop this bean from being garbage collected ?
  • 2) what would be the best way to create the bean ?


  • something like this ? :
    [CODE}
    appBean myAppBean = (appBean) getServletContext().getAttribute("myAppBean");
    if (myAppBean==null)
    {
    appBean myAppBean = new appBean();
    myAppBean.getData();
    getServletContext().setAttribute("myAppBean");
    }
    [/CODE]
    and then reference it in jsp's by :

  • 3) should the bean be created as a singleton ?


  • Steve
    19 years ago
    Kevin,
    Thanks for your replies - I was wondering if there was a completely different technique. I've seen code using Principals but I'm not clear how it works or if the client needs something on their workstation first. I feel sure other Java users must have been faced with this problem and resisted using IIS.
    <BR/><BR/>
    My fear with NTLM is :
  • what happens if the offsets were to change
  • do all browsers use it
  • there can be problems if the user sets the security level to high
  • <BR/><BR/>
    Are you familiar with any non NTLM techniques ?
    Steve
    19 years ago
    http://www.jguru.com/faq/view.jsp?EID=1045412

    This link shows a technique for getting the users Windows login + domain. But it uses hardcoded offsets. Is there a cleaner way of doing it ?
    19 years ago
    CL,
    I think the problem is a network problem (the SMTP server chap started talking about reverse pings ..),
    on odd occasions the smtpclient isn't created properly, and this is what I was trying to handle.

    Looking back at your first reply you seem to have separate threads for IO probably for this reason.

    I would appreciate being able to see a code example from your website, if it's not too complicated
    and if you could direct me to a suitable piece of code I'd be grateful.

    I was wondering if the application could have 3 goes at creating the smtpclient, and putting a time limit
    of say 2 seconds on each attempt to create the client.

    In pseudo-code I was thinking of something like :


    clientcreated=false;

    loop (3 times while clientcreated=false)

    create thread

    loop (for 2 seconds while clientcreated=false)
    end loop

    if (clientcreated=false)
    cancel thread

    end loop

    if (clientcreated=false)
    error

    thread
    {
    create smtpclient
    clientcreated=true
    }


    Remembering that the rest of the application is synchronised, this shouldn't hold up other users
    except when there is this intermittent problem, and then only for 6 seconds.

    But again it may not make sense to have a thread in a synchronised application.