Results 1 to 14 of 14
  1. #1
    SE123 is offline Member
    Join Date
    Sep 2009
    Posts
    9
    Rep Power
    0

    Default Alternative of FileInputStream to read Property File

    Hi,
    I am reading one property file in my doGetMethod of servlet.
    For that I am using the below code:

    Properties props = new Properties();
    props.load(new FileInputStream(path+"abc.property"));

    but I think it will adversely impact on the performance.
    What can be the alternate solution to achive this? I can't read this in init method because the path of property file is retrieving from request.

    Thanks in advance?

  2. #2
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    841
    Rep Power
    6

    Default

    Hi,
    Once if the request is received ,just put the path in session.
    If the session value is null,then accept the request path or else take the value from session itself.No need to get it from request each time.
    Ramya:cool:

  3. #3
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Where are the properties file residing on the server? Remember that your application is run on a web server?

  4. #4
    SE123 is offline Member
    Join Date
    Sep 2009
    Posts
    9
    Rep Power
    0

    Default

    Quote Originally Posted by RamyaSivakanth View Post
    Hi,
    Once if the request is received ,just put the path in session.
    If the session value is null,then accept the request path or else take the value from session itself.No need to get it from request each time.
    No, putting the path in session won't resolve my problem because I am concern about multiple requests hits at a time and for every hit servlet will go for I/O operation.

  5. #5
    SE123 is offline Member
    Join Date
    Sep 2009
    Posts
    9
    Rep Power
    0

    Default

    Quote Originally Posted by r035198x View Post
    Where are the properties file residing on the server? Remember that your application is run on a web server?
    My property file is placed in the same level of WEB-INF i.e. it is not inside the WEB-INF or set into the class path.

  6. #6
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    841
    Rep Power
    6

    Default

    one time u read and keep the file.Next time onwards ,no need to do the same.It got stored in session know?
    Ramya:cool:

  7. #7
    SE123 is offline Member
    Join Date
    Sep 2009
    Posts
    9
    Rep Power
    0

    Default

    Quote Originally Posted by RamyaSivakanth View Post
    one time u read and keep the file.Next time onwards ,no need to do the same.It got stored in session know?
    No, but session will remain valid for per request means many users will hit the servlet many times and per request one session got created that means even to do so file will be accessed many times. I agree if same user in same session will submit the form won't require to access the file again and it will take from session. But my concern is about multiple requests hit at same time.

  8. #8
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    841
    Rep Power
    6

    Default

    My question here is whether propertyfile is common for all request?
    Ramya:cool:

  9. #9
    SE123 is offline Member
    Join Date
    Sep 2009
    Posts
    9
    Rep Power
    0

    Default

    Quote Originally Posted by RamyaSivakanth View Post
    My question here is whether propertyfile is common for all request?
    yes, it is common for all requests.

  10. #10
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    841
    Rep Power
    6

    Default

    then put it in application scope.Till the server is web server is running it will
    Ramya:cool:

  11. #11
    SE123 is offline Member
    Join Date
    Sep 2009
    Posts
    9
    Rep Power
    0

    Default

    Quote Originally Posted by RamyaSivakanth View Post
    then put it in application scope.Till the server is web server is running it will
    Could you provide a snippet to do so?

  12. #12
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    841
    Rep Power
    6

    Default

    For example u should do like this below.

    getServletContext().setAttribute("path","some value")
    Ramya:cool:

  13. #13
    SE123 is offline Member
    Join Date
    Sep 2009
    Posts
    9
    Rep Power
    0

    Default

    Quote Originally Posted by RamyaSivakanth View Post
    For example u should do like this below.

    getServletContext().setAttribute("path","some value")
    so do I need to set this attribute under init method or can I go ahead with doGet() itself?

  14. #14
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    841
    Rep Power
    6

    Default

    U can set in service.Because u told know u are going to get the info from request.Then,how can u do in init()?
    Ramya:cool:

Similar Threads

  1. Replies: 0
    Last Post: 12-01-2008, 09:50 PM
  2. File Property
    By Juggler in forum New To Java
    Replies: 0
    Last Post: 08-10-2008, 07:23 AM
  3. How to store property file into key value pair
    By Java Tip in forum java.util
    Replies: 0
    Last Post: 04-05-2008, 10:16 AM
  4. Initializing property object from a file
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-29-2007, 04:55 PM
  5. Property File
    By Peter in forum JDBC
    Replies: 2
    Last Post: 07-04-2007, 03:48 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •