• 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

A typical Web Development problem: (login checking,etc)

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my homework, i had to build a site, about e-learning. Basic framework is: login, then have several functions and have various link of note and course material, like this: click here to see
I use a so called Model View Controller method: I need to write a servlet as the single point of contact. This controller servlet will check if the user has logged in. If so, it will forward to the main menu page. Otherwise, it will forward to the login page. So all the functions like Student Info, Chat room, after logined will point to http://localhost/servlet/container which check the session first, then redirect to related functions' Servlet (student info,chat room,etc), but my PROBLEM is that: as you see my pic above, if I use these method for my course material on the right, it will be very bulky, because all the courses material will link to the container first, then redirect to another Servlet to resolve the REAL link in Web-inf, (to prevent viewing without login). Do I present my question clearly? If not, I will explain further. Please kindly suggest what way I can solve, thanks!!
 
Ranch Hand
Posts: 732
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok , i think i undersatnd your problem but im not sure.
how about this:
in the login servlet, if the login is successful then set a session attribute with the user name in it (and password if u wish).
in each of your other servlets that represent the functions chat etc... check with an if statement if the attribute of a user name is there.
if it isnt then redirect to the login one again.
does that solve your problem?
 
Tazzmission
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, main problem is here-->
Originally, my idea is like yours, and I really build several javas: login.java, Userlog.java (This is user's object, with username and password), other functional java for checking the session. I placed all this java in the same directory, they work. But if those functional java are placed in directories different from login.java (which create the session), ERROR will be occur. So I wonder if I can't do in this way. Everyfile using the session object MUST be in the SAME directory? Correct me if im wrong. thanks
 
Roy Ben Ami
Ranch Hand
Posts: 732
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what kind of web server are u using?
i know that for tomcat for example you put al your servlets files in the classes directory and the jsp in the root .
doesnt concern the session.
however im sure u can change the web.xml to point to differnt directories.
anyway, whats the problem of all the files being in the same directory? or package?
 
Tazzmission
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
no ,what i mean login servlet/user object AND other functional servlet should be in different directory locially. However, im not success in calling back the same object through Servlet in another directories. Say, login.java (create/check session), userLog.java(user Object:username,password,getUsername,getPasswd), chatroom.java, etc.java in the same directory. chatroom.java will check the session object firstly, no problem. But if i move chatroom to another directory, when checking the session object it will be error.

Another thing is, this technique is also bulky for course material, if I've 100 course material in htm, then i will need to write 100jsp for them? too complex. This problem is troublesome.
 
Roy Ben Ami
Ranch Hand
Posts: 732
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i see you problem.
first of all in a web application its better if u got the whole files organized correctly in the right directories.
and second i think we are back to the starting position.
you are right, it is too bulky to make 100 html to jsp just for that.
then in that case, i would suggest to try using the filters capability of the servlets 2.3 API.
i'm not too familiar with that but i know it can solve your problem.
with the filters u can filter a request to a new page and allow it go thru only if the user is login.
there is a good example of filters in the pet store example at the java site.
 
Tazzmission
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
thanks, where can have more examples about filtering on login topic?
Also, before Servlet 2.3 API, that should be many web site dealing this kind of problem (I think it's not a problem to them) I wonder what approach they are using? Without Servlet 2.3API or even Servlet, they may use PHP, etc. But it's not a problem to them, we just don't know what approaches or technique they are using.
 
reply
    Bookmark Topic Watch Topic
  • New Topic