Results 1 to 8 of 8
Thread: Problem with setAttribute()
- 02-08-2009, 10:56 PM #1
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:
- 02-09-2009, 04:52 AM #2
Senior Member
- Join Date
- Sep 2008
- Posts
- 564
- Rep Power
- 5
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.
- 02-09-2009, 11:37 AM #3
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.............
- 02-09-2009, 11:54 AM #4
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 8
- 02-09-2009, 12:06 PM #5
Hey Masi,
Seems you have the link for every answer :rolleyes:i am the future
- 02-09-2009, 12:28 PM #6
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 8
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.
- 02-09-2009, 12:38 PM #7
i apologise if you felt offended :eek:, but i was just praising you :o
i am the future
- 02-09-2009, 01:06 PM #8
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 8
Similar Threads
-
Difference between Session.setAttribute and System.setProperty
By Kavit Gamot in forum New To JavaReplies: 2Last Post: 01-27-2009, 04:11 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks