Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

JSP and beans

  • 30-10-2006 05:18PM
    #1
    Closed Accounts Posts: 10


    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;
    }
    }


Comments

  • Registered Users, Registered Users 2 Posts: 33 TabulaRasa


    Looks like you're class Check is in the default package but your JSP is attempting to use com.detiel.advjhtp1.jsp.beans.Check. So it looks like you need to declare your class in a package.


  • Registered Users, Registered Users 2 Posts: 5,618 ✭✭✭Civilian_Target


    Yeah, it's not actually finding your bean. Check your paths match your specfied package, etc. Have you considered using a JNDI lookup instead?


Advertisement