Results 1 to 8 of 8
  1. #1
    R O C K Y's Avatar
    R O C K Y is offline Member
    Join Date
    Feb 2009
    Posts
    19
    Rep Power
    0

    Question Problem with setAttribute()

    hey i want to send output from servlet file to jsp page as i need to display the count field value for the no of times the site is being visited.

    jsp page --->welcome.jsp
    sevlet ---->hitCountHandler.java

    as soon as the welcome file is loaded , i want to display the 'count' value from servlet in the control 'hitCountField' of jsp page by trying this:-


    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {

    String countValue = String.valueOf(++count);//static int count;


    RequestDispatcher requestDispatcher = getServletContext().getRequestDispatcher("/welcome.jsp");

    request.setAttribute("hitCountField.value", countValue);
    requestDispatcher.forward(request,response);

    }

    prblm1:
    but unable to produce the 'count' value from servlet to jsp control 'hitCountField', it shows null.

    prblm2:
    how to load count value at load time of first jsp page ->welcome.jsp , i mean to ask which control of jsp page would trigger the servlet at load time of jsp page OR please provide any other solution if exists.

    waiting for your reply.........:mad:

  2. #2
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    7

    Default

    for your first problem, where does the null value originate? do you pass in a null value to the jsp, or does the jsp get a null value from the servlet? how do you get the value in the jsp?

    i don't really understand your second problem.

  3. #3
    R O C K Y's Avatar
    R O C K Y is offline Member
    Join Date
    Feb 2009
    Posts
    19
    Rep Power
    0

    Default

    prblm1:
    when i pass nothing in the textfield, it returns nothing in that textfield of jsp page even after it sets the new value from the doget() of servlet , setting its new value as a counter , but this counter value is not displayed in the jsp page after visiting servlet using request dispatcher , i need to show the count value in that hitcountfield(textfield) of the jsp page.

    prblm2:
    as soon as someone visits my website , i need to show the incremented global counter value on the jsp page using servlet

    is there any way to implement the above two things?please suggest if exists!!!

    i think now u understand the problem.............

  4. #4
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

  5. #5
    rjuyal's Avatar
    rjuyal is offline Senior Member
    Join Date
    Mar 2008
    Location
    Delhi, India
    Posts
    194
    Rep Power
    7

    Default

    Hey Masi,
    Seems you have the link for every answer :rolleyes:
    i am the future

  6. #6
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Quote Originally Posted by rjuyal View Post
    Hey Masi,
    Seems you have the link for every answer :rolleyes:
    Nothing wrong with making them do some reading on their own, and, when it is already written, there is no reason to repeat that here. If you prefer to provide cut-n-paste capable code, go ahead. That helps them, not at all, however. Or, if you prefer to spend a couple hours reproducing something that already exists, once again, go ahead.

  7. #7
    rjuyal's Avatar
    rjuyal is offline Senior Member
    Join Date
    Mar 2008
    Location
    Delhi, India
    Posts
    194
    Rep Power
    7

    Default

    i apologise if you felt offended :eek:, but i was just praising you :o
    i am the future

  8. #8
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    No problem, it's been a hard few days, recently, but the "rolleyes" definately made it seem sarcastic.

Similar Threads

  1. Replies: 2
    Last Post: 01-27-2009, 05:11 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
  •