Search code examples
jspscriptlet

How to access a variable present in a scriptlet tag in some other scriptlet tag in JSP?


if i do this, it says "cannot find symbol:x". Is there anyway i can access x outside that scriptlet tag?

<%
String x="abc";
%>
<%
System.out.println(x);
%>

Solution

  • You can access x by expression tag(<%= %>). You can try the following code :

    <%
    String x="abc";
    %>
    <%=x %>