Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

problem during create thread in jsp  RSS feed

 
sandy mahajan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
i want to show Time through jsp. i use System.currentTimeMillis() method to show time & convert it into min.
But i have to put these code into thread. code as follows

Thread th = new Thread();

th.start();


%><%! long ctm;
int game_timer;
void run()
{
try
{
ctm=System.currentTimeMillis();
%>currTimeMillis2 &bsp;<%=ctm%><br/><%
game_timer=(int)ctm;
static int day;
static int hrs, min;
hrs = (game_timer/60)%24;
day = 1+(game_timer/60)/24;
min = (game_timer%60);
%>Time--<%=hrs%>:<%=min%><br/><%
}
catch (Exception e)
{
%><%=e%><br/><%
}
}
%>

Eroor:
Generated servlet error:
C:\Program Files\Apache Software Foundation\Tomcat 5.0\work\Catalina\localhost\Bollywood-Crossword\org\apache\jsp\jsp\Play_jsp.java:27: illegal start of expression
private static java.util.Vector _jspx_dependants;
^


Generated servlet error:
C:\Program Files\Apache Software Foundation\Tomcat 5.0\work\Catalina\localhost\Bollywood-Crossword\org\apache\jsp\jsp\Play_jsp.java:29: illegal start of expression
public java.util.List getDependants() {
^
2 errors

Please show me the way.....

Thanks.
 
Chris Hurst
Ranch Hand
Posts: 443
3
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suspect your miles of base I'ed need to see the full jsp code and exactly what you intended, I suspect you don't want to create thread at all, what is your thread trying to do ? The jsp compilation errors don't match up with your code fragment.

Do you want a web page with an updating time ? Do you want your web page to pull the time from the server reqularly or just display the time statically (once) at startup.

I suspect this should really be posted in one of the web forums.
 
sandy mahajan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi chris,
iam developing games in jsp, in this game iam showing crossword & player has to find out the correct names & submit through input box. but my moto is that player has to find these names from the crosswords in some time limit.
so i want to show timer of 5 min. & player has to find maximum names within 5 min outerwise player will loose the game.
I already code that generate Bollywood Crosswords on browser & now i just need to show 5 min time limit.
complete code without timer:

<body>
<%


String gameId=request.getParameter("gameId");
if(gameId==null)
gameId="start";
String moves=request.getParameter("moves");
if(moves==null)
moves="0";
int gmoves=Integer.parseInt(moves);


String row1[]={"K","A","R","E","E","N","A","H"};
String row2[]={"O","A","C","D","E","F","G","H"};
String row3[]={"Y","B","J","D","E","F","G","H"};
String row4[]={"L","B","C","O","E","F","G","H"};
String row5[]={"A","B","C","D","L","F","G","H"};


String corrAns[]={"Abhi","shah","amir","salmaan","kajol","amrita","tabu","madhuri"};


String userAns=request.getParameter("userAns");
if(userAns==null || (userAns!=null && userAns.equals("")))
userAns="-";



int answer=0;
if(!userAns.equals("-"))
{
int index;
for(index=0;index<corrAns.length;index++)
{
if(corrAns[index].equals(userAns))
{ %>

<b>Good! Correct Answer</b><br/>
<% }
}

if(!corrAns[index].equals(userAns))
{ %>

<b>Sorry! Wrong Answer.</b><br/>

<% }
}




%>

<br/>
<b>Bollywood Crossword</b><br/>

<%
if(gameId.equals("start"))
{
String s="";

for(int i=0;i<row1.length;i++)
{
s=row1[i]+" ";
%><%=s%><%
}
%><br/><%
for(int j=0;j<row2.length;j++)
{
s=row2[j]+" ";
%><%=s%><%
}
%><br/><%
for(int j=0;j<row3.length;j++)
{
s=row3[j]+" ";
%><%=s%><%
}
%><br/><%
for(int j=0;j<row4.length;j++)
{
s=row4[j]+" ";
%><%=s%><%
}
%><br/><%
for(int j=0;j<row5.length;j++)
{
s=row5[j]+" ";
%><%=s%><%
}
%>

<br/>
Find out all bollywood stars in a minimum time ...<br/>
Click here to begin: <br/>
<form action="<%=rootpath%>">
<input type="hidden" name="_rapsvc" value="<%=_rapsvc%>" />
<input type="hidden" name="_svc" value="<%=_rapsvc%>" />
<input type="hidden" name="_raptype" value="SERVICE" />
<input type="hidden" name="gameId" value="starting" />
<input type="hidden" name="req_id" value="3" />


<br/>

<input type="submit" name="sbmt" value="Start Game" />
</form>

<%
}
else if(gameId.equals("win"))
{
%>


<br/>
!!Congrats!!<br/>
You have done it
<%
}
else
{
gameId="started";
String s="";

for(int i=0;i<row1.length;i++)
{
s=row1[i]+" ";
%><%=s%><%
}
%><br/><%
for(int j=0;j<row2.length;j++)
{
s=row2[j]+" ";
%><%=s%><%
}
%><br/><%
for(int j=0;j<row3.length;j++)
{
s=row3[j]+" ";
%><%=s%><%
}
%><br/><%
for(int j=0;j<row4.length;j++)
{
s=row4[j]+" ";
%><%=s%><%
}
%><br/><%
for(int j=0;j<row5.length;j++)
{
s=row5[j]+" ";
%><%=s%><%
}
%>


<br/>
Score: <%=gmoves%><br/>
<form action="<%=rootpath%>">
Enter the word
<input type="input" value="" name="userAns" /><br/>


<input type="hidden" value="<%=gmoves%>" name="moves" />
<input type="hidden" value="<%=gameId%>" name="gameId" />
<input type="hidden" name="_rapsvc" value="<%=_rapsvc%>" />
<input type="hidden" name="_svc" value="<%=_rapsvc%>" />
<input type="hidden" name="_raptype" value="SERVICE" />
<input type="hidden" name="req_id" value="3" />

<br/>

<input type="submit" name="sbmt" value="Submit" />
</form>
<%
}
%>
<br/>
<a href="<%=rootpath%>&req_id=3">Restart</a></br>
<a href="<%=rootpath%>&req_id=2">Menu</a></p>

</body>
<%
}
%>
</html>
still crossword are not arrange. ijust check userAns with corrAns.
i think you got my point what actually i want to show..

Thanks
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I haven't looked at the code, but anything complicated enough to use threads should not be done in a JSP (which is just for generating an HTML view, not for running any computations). Use servlets instead.
 
Chris Hurst
Ranch Hand
Posts: 443
3
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok, you definitely DON'T want a thread, assuming you want to do this with JSP and not an applet what would be another solution (in which case you could have java and threads) . The problem with a thread in your case is you want it to work client side not server side.

Looks like you need some javascript embedded in your jsp, you add javascript to your jsp in the same way you add html. (note there are sure to be clock stype javascripts libs out there you could just use)

Using the window.setTimeout method you can call back a javascript method at a given time interval say every few seconds and then adjust the clock i.e. if the the time was a static bit of text you set the text to the new time and the browser will automatically show the result obviously if time > 5 mins then you set the text to time. (you could alternatively use a server clock via refreshes or AJax requests but thats just overkill)

There is bound to loads of examples of this kind of thing on the net my books are full of them
 
sandy mahajan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks chris, i got your points.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!