当前位置: 代码迷 >> Java相关 >> [求助],怪事!!!老大,帮 一帮呀
  详细解决方案

[求助],怪事!!!老大,帮 一帮呀

热度:372   发布时间:2004-08-12 00:23:00.0
[求助],怪事!!!老大,帮 一帮呀

<% if(numGuess.getSuccess())%> <% { %> Congratulation! You got it And after just<%=numGuess.getNumGuesses()%>tries.<p> <% numGuess.setInit(); %> Care to <a href="numGuess.jsp">try again</a>? <% } %> <% else if(numGuess.getNumGuesses()==0)%> <% { %> Welcome to the Number Guess game.<p> I'm thinking of a number between 1 and 100.<p> <form method="get"> What's your guess?><input type="text" name="guess"> <input type="submit" value="Submit"> </form> <% }else{ %> Good guess,but nope. Try<b><%=numGuess.getHint()%></b> You have made<%=numGuess.getNumGuesses()%>guesses.<p> I'm thinking of a number between 1 and 100.<p> <form method=get> What's your guess?<input type=text name=guess> <input type=submit value="Submit"> </form> <% } %>

怎么总是报错呀

[javac] C:\Tomcat 4.1\work\Standalone\localhost\test\numGuess_jsp.java:81: 'else' without 'if' [javac] else if(numGuess.getNumGuesses()==0) [javac] ^ [javac] C:\Tomcat 4.1\work\Standalone\localhost\test\numGuess_jsp.java:91: 'else' without 'if' [javac] }else{ [javac] ^ [javac] 2 errors

[此贴子已经被作者于2004-08-12 01:19:49编辑过]

搜索更多相关的解决方案: 怪事  老大  

----------------解决方案--------------------------------------------------------

完整的代码:

<%@ page contentType="text/html;charset=gb2312" %> <%@ page import="num.numGress" %> <jsp:useBean id="numGuess" scope="session" class="num.numGuess" /> <jsp:setProperty name="numGuess" property="*" /> <html> <head> <title>测试</title> <head> <body bg="white"> <font size="4"> <% if(numGuess.getSuccess())%> <% { %> Congratulation! You got it And after just<%=numGuess.getNumGuesses()%>tries.<p> <% numGuess.setInit(); %> Care to <a href="numGuess.jsp">try again</a>? <% } %> <% else if(numGuess.getNumGuesses()==0)%> <% { %> Welcome to the Number Guess game.<p> I'm thinking of a number between 1 and 100.<p> <form method="get"> What's your guess?><input type="text" name="guess"> <input type="submit" value="Submit"> </form> <% }else{ %> Good guess,but nope. Try<b><%=numGuess.getHint()%></b> You have made<%=numGuess.getNumGuesses()%>guesses.<p> I'm thinking of a number between 1 and 100.<p> <form method=get> What's your guess?<input type=text name=guess> <input type=submit value="Submit"> </form> <% } %> </font> </body> </html>

其中numGuess.java:

package num; import java.util.*;

public class numGuess { private int answer; file://private int g; private int numGuesses; file://private String guess; private String hint; private boolean success; public numGuess() { setInit(); } public void setGuess(String guess) { numGuesses++; int g; try { g=Integer.parseInt(guess); }catch(Exception e) { g=-1; } if(g==answer) { success=true; } else if(g==-1) { hint="a number next time"; } else if(g>answer) { hint="lower"; } else { hint="higher"; } } public boolean getSuccess() { return success; } public String getHint() { return hint; } public int getNumguesses() { return numGuesses; } public void setInit() { answer=Math.abs(new Random().nextInt()%100)+1; success=false; numGuesses=0; } }


----------------解决方案--------------------------------------------------------
乍一看好像没问题,不过我也没弄过JSP不过有一点你不知道注意了没有,tomcat服务器重启了吗?我曾经帮过一个朋友,他就是没有重启所以没有加载最新的类,导致怎么改都是错
----------------解决方案--------------------------------------------------------
好像是程序的问题吧 再仔细看看吧
----------------解决方案--------------------------------------------------------
  相关解决方案