Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doubt in page 494 of HFSJ

 
swapna rao
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a doubt in understanding <jsp aram> variable scope.
Just for testing i wrote the following code inside a Test.jsp.
<form action="TestServlet>
<jsp:include page="hello/second.jsp">
<jsp aram name="username" value="marcus"/>
</jsp:include>
<%
out.print(request.getParameter("username"));
%>
</form>
This JSP displays the username value as null which is valid.But,i would like to know what is scope of <jsp aram > variables .If i submit the above form to TestServlet ,will i able to retrieve username value.I even tested by submitting the value to TestServlet and i got username value as "null".What is the scope of <jsp aram> variables ? Will it be available only to the included page.If so,how it is different from tag files. When we use tag files,we use tag attributes which are visible only in inculded pages.
 
Chethan C Gowda
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Scope of <jsp aram --- > is Request but you can access it only in hello/second.jsp file, not in TestServlet.
There is no much difference between <jsp:include> and Tag, One major difference is if you use <jsp:include> you are going to land up with nested two <html> opening and </html> closing tags.
Take for example,if you include a page using <jsp:include> :

<%@ page import="...." %>
<html> <body>
<jsp:include page="hello/second.jsp">
<jsp: param name="username" value="marcus"/>
</jsp:include>
</body> </html>

hello/second.jsp
<html> <body> <%=request.getParameter("username"); %> </body> <html>

Your final JSP page will end up with repetition of tags. In order to aviod this you can go for Tags.
To tag file, you dont send request parameters, you send tag attributes.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic