• Post Reply Bookmark Topic Watch Topic
  • New Topic

JSP andBeans

 
Anto Keogh
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a long one.
I badly need some help with this. It is a project for college it is a number guess game I had the code working but then something happened and I keep getting this error:

javax.servlet.ServletException: com/detiel/advjhtp1/jsp/beans/Check
(wrong name: Check)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:272)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

and I don't know what it means Can any one help.
The code for the JSP is:

<jsp:useBean id = "check" scope = "session"
class = "com.detiel.advjhtp1.jsp.beans.Check"/>

<html>
<head>
<title>Number Guess</title>
</head>


<body>
<% if (check.getWin()) { %>

You've won after <%= check.getNumGuesses() %> tries.<p>

<% check.reset(); %>

Do you want to <a href="numguess.jsp">try again</a>?

<% } else if (check.getNumGuesses() == 0) { %>

Pick a number between 1 and 10.<p>

<form method=get>
Enter your guess. <input type=text name=guess>
<input type=submit value="Submit">
</form>

<% } else { %>

Nope. Try <b><%= check.getTip() %></b>.

You have made <%= check.getNumGuesses() %> guesses.<p>

I'm thinking of a number between 1 and 10.<p>

<form method=get>
Enter your guess. <input type=text name=guess>
<input type=submit value="Submit">
</form>

<% } %>


</body>
</html>


and the code for the Bean is:


import java.util.*;

public class Check
{

int answer;
boolean win;
String tip;
int numGuesses;

public Check()
{
reset();
}

public void setGuess(String guess)
{
numGuesses++;

int i;

i = Integer.parseInt(guess);

{
i = -1;
}

if (i == answer)
{
win = true;
}
else if (i == -1)
{
tip = "a number next time";
}
else if (i < answer)
{
tip = "higher";
}
else if (i > answer)
{
tip = "lower";
}
}

public boolean getWin()
{
return win;
}

public String getTip()
{
return "" + tip;
}

public int getNumGuesses()
{
return numGuesses;
}

public void reset()
{
answer = Math.abs(new Random().nextInt() % 100) + 1;
win = false;
numGuesses = 0;
}
}


Thanks for any help you can give.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
javax.servlet.ServletException: com/detiel/advjhtp1/jsp/beans/Check
(wrong name: Check)


This usually means the class file is screwed up in some way.

Have you tried rebuilding it?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anto,
Javaranch tip:

If you are going to post more than a line or two of your code, wrap that
code in a set of UBB Code tags.
Doing so will help to preserve your code's indenting, making it easier to read.
If it is easier to read, more people will actaully read it and you will
stand a better chance of getting help with your question.
See UseCodeTags for more
help with UBB code tags.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Anto Keogh:

..and the code for the Bean is:

import java.util.*;

public class Check
{
...


I don't see a package declaration in your bean's source but your are specifying one in the useBean tag:

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!