Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within JSP
Search Coderanch
Advance search
Google search
Register / Login
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
Forum:
JSP
can't get the value from the servlet in JSP
Ma Yao
Greenhorn
Posts: 14
posted 10 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I wrote the code in
jsp
:
<form method = "get" action = "/Firstiraq"> The current Yes count is: <c:out value="${param.yescount}" /> </br> The current No count is : <c:out value="${param.nocount}" /> </form>
then in the
servlet
I wrote this:
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); ResultSet accountnum; try { accountnum = pstmt.executeQuery(); if(accountnum.next()){ int yescount = accountnum.getInt(2); int nocount = accountnum.getInt(3); request.setAttribute("yescount", yescount); request.setAttribute("nocount", nocount); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } out.flush(); out.close(); }
I get the result with:
The current Yes count is:
The current No count is:
and can't get the attribute, someone could tell me the reason, thanks.
Bear Bibeault
Sheriff
Posts: 67746
173
I like...
posted 10 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
You do not use the
param
builtin to access scoped variables. So:
${yescount}
[
Asking smart questions
] [
About Bear
] [
Books by Bear
]
Ma Yao
Greenhorn
Posts: 14
posted 10 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Still the same problem after using the EL expression ${}
Bear Bibeault
Sheriff
Posts: 67746
173
I like...
posted 10 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
${} is not a valid expression.
[
Asking smart questions
] [
About Bear
] [
Books by Bear
]
Ma Yao
Greenhorn
Posts: 14
posted 10 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
${}the EL expression.
I also add the lib :
<%@ taglib uri="http://java.sun.com/jsp/jstl/c
Surendra Kumar
Ranch Hand
Posts: 236
posted 10 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
where in your servlet are you forwarding to the JSP?
You have to use RequestDispatcher to forward to the JSP, isn't it?
Consider Paul's
rocket mass heater
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
method showing different returns when declared on JSP or Servlet
Passing multiple rows from Servlet to JSP
How to execute a function from servlet on JSP start up
Need some help in setting up a url parameter into a form bean
More...