Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

JSP and beans

  • 30-10-2006 4: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