• Post Reply Bookmark Topic Watch Topic
  • New Topic

Setting attributes from JSP to Servlet  RSS feed

 
Husam Haddad
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anybody help me ??? thanks
JSP code:
...
<%
request.setAttribute("name", "Husam Haddad");
%>
...//forwarding to servlet using the form HTML tag

Servlet code:
{
...
String name = request.getAttribute("name");
System.out.println("name is " + name);
...
}

the output is : name is null

why is null ?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
forwarding to servlet using the form HTML tag


That is most decidedly not a forward.

When the HTML page is delivered to the browser, the request goes out of scope and with it the request scoped variable.

For some basic understanding of how JSPs work, please read this article.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!