Reputation: 664
i am really new to java, and jsp. so it is understandable that i cant really understand the scope of parameters here is my code:
<%@page contentType="text/html" pageEncoding="UTF-8" %>
<%!
String sRony= new String();
void func() {
sRony += " - add in func() - ";
}
%>
<%
if (request.getParameter("ron")!= null){
sRony = request.getParameter("ron");
func();
}
if (request.getParameter("sleep")!= null){
Thread.sleep(2000);
}
%>
<html>
<head>
</head>
<body>
<%=sRony%><%= new java.util.Date() %>
</body>
</html>
the problem is that this code is not thread safe. if you'll surf to
page.jsp?ron=sleep&sleep=1
and at the same time to
page.jsp?ron=no_sleep
both page will print the "no_sleep", cause the parameter sRony is global.
if i'll remove the !
from <%!
the parameter sRony will not be recognized inside void func()
i cant figure out how can i declare a parameter that will be per request, and will have the scope inside my function.
not sure if my platform is important information, i am working on redhat 5.5 64 bit, glassfish server 3.
any help ?
Upvotes: 0
Views: 257
Reputation: 240860
use pagescope
and use JSTL instead javacode
<c:set var="name1" value="value1" scope="page" />
Upvotes: 1