Anshul Singhal wrote:I ve this piece of code in 1.jsp
<%request.setAttribute("variable","anshul");%>
<form action="2.jsp">
<input type="submit" value="Click" />
</form>
2.jsp
<%
String q = (String)request.getAttribute("variable");
out.println(q);
%>
it is printing null value
Hi Anshul ,
Welcome to JavaRanch
, You may create a new
thread for your question(s) since this is bit different from the original question. This "<%request.setAttribute("variable","anshul");%>" works only for the request scope which within the request to the 1.jsp and the response it generates. Once you get the response that attribute is out of scope inside the server. So that won't work. You may store the attribute in a more wider scope that is may be HttpSession, ServletContext but that will depend on your requirement.