JSP and EJBs

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • star111792
    New Member
    • Jan 2007
    • 26

    #1

    JSP and EJBs

    helo all

    i am working with JSP and EJBs. i have written a simple code for verifying username and password of user by using session beans. my problem is that i am getting the following error:


    HTTP Status 500 -

    --------------------------------------------------------------------------------

    type Exception report

    message

    description The server encountered an internal error () that prevented it from fulfilling this request.

    exception

    org.apache.jasp er.JasperExcept ion: Unable to compile class for JSP

    An error occurred at line: 15 in the jsp file: /Verify.jsp
    Generated servlet error:
    Type mismatch: cannot convert from boolean to Boolean


    org.apache.jasp er.compiler.Def aultErrorHandle r.javacError(De faultErrorHandl er.java:84)
    org.apache.jasp er.compiler.Err orDispatcher.ja vacError(ErrorD ispatcher.java: 328)
    org.apache.jasp er.compiler.JDT Compiler.genera teClass(JDTComp iler.java:397)
    org.apache.jasp er.compiler.Com piler.compile(C ompiler.java:28 8)
    org.apache.jasp er.compiler.Com piler.compile(C ompiler.java:26 7)
    org.apache.jasp er.compiler.Com piler.compile(C ompiler.java:25 5)
    org.apache.jasp er.JspCompilati onContext.compi le(JspCompilati onContext.java: 556)
    org.apache.jasp er.servlet.JspS ervletWrapper.s ervice(JspServl etWrapper.java: 293)
    org.apache.jasp er.servlet.JspS ervlet.serviceJ spFile(JspServl et.java:314)
    org.apache.jasp er.servlet.JspS ervlet.service( JspServlet.java :264)
    javax.servlet.h ttp.HttpServlet .service(HttpSe rvlet.java:810)
    org.jboss.web.t omcat.filters.R eplyHeaderFilte r.doFilter(Repl yHeaderFilter.j ava:81)


    note The full stack trace of the root cause is available in the Apache Tomcat/5.5.9 logs.


    --------------------------------------------------------------------------------

    Apache Tomcat/5.5.9



    im using jboss-4.0.2

    im also presenting code for ur consideration


    VerifyUser.java
    ------------------------


    package hina.mahmood;


    import javax.ejb.*;
    import java.rmi.*;


    public interface VerifyUser extends javax.ejb.EJBOb ject
    {

    public boolean Verify(String user, String pswd) throws RemoteException ;


    }// end interface

    ---------------------------------------------------------------------------

    VerifyUserHome. java
    -------------------------------


    package hina.mahmood;

    import javax.ejb.*;
    import java.rmi.*;
    import javax.ejb.EJBHo me;


    public interface VerifyUserHome extends javax.ejb.EJBHo me
    {

    public VerifyUser create() throws RemoteException ,CreateExceptio n;


    }// end interface

    --------------------------------------------------------------------------------

    VerifyUserBean. java
    -------------------------------


    package hina.mahmood;



    import javax.ejb.*;
    import java.rmi.*;
    import java.sql.*;


    public class VerifyUserBean implements SessionBean
    {

    private SessionContext ctx;



    public Boolean Verify(String user,String pswd) throws RemoteException
    {

    int flag=0;
    Boolean bool=new Boolean("false" );


    try{
    Class.forName(" sun.jdbc.odbc.J dbcOdbcDriver") ;
    Connection con=DriverManag er.getConnectio n("jdbc:odbc:ho nie");
    Statement stmt=con.create Statement();
    String query="Select username,passwo rd from hina";
    ResultSet rs=stmt.execute Query(query);

    while(rs.next() )
    {
    if((rs.getStrin g("username").e quals(user))&&( rs.getString("p assword").equal s(pswd)))
    {
    flag=1;
    break;

    }
    }// end while



    }// end try


    catch(Exception e)
    {System.out.pri ntln(e);}




    if(flag==0)
    {
    bool=new Boolean("false" );
    return bool;
    }


    else
    if(flag==1)
    {
    bool=new Boolean("true") ;
    return bool;
    }


    return bool;



    }// end method



    public void ejbcreate() throws RemoteException ,CreateExceptio n
    {



    }// end method




    public void setSessionConte xt(SessionConte xt ctx)
    {
    this.ctx=ctx;
    }



    public void ejbPassivate()
    {}


    public void ejbActivate()
    {}



    public void ejbRemove()
    {}


    }// end class

    ----------------------------------------------------------------------------

    Verify.jsp is tha page that uses the session bean

    -------------------------------------

    <%@ page import="java.rm i.*,javax.namin g.Context,javax .naming.Initial Context,hina.ma hmood.*"%>


    <%

    String username=reques t.getParameter( "user");
    String password=reques t.getParameter( "pswd");

    InitialContext cxt=new InitialContext( );

    Object obj=cxt.lookup( "VerifyUser ");

    VerifyUserHome userHome=(Verif yUserHome)javax .rmi.PortableRe moteObject.narr ow(obj,VerifyUs erHome.class);


    VerifyUser vs=userHome.cre ate();


    Boolean b=vs.Verify(use rname,password) ;

    boolean bool=b.booleanV alue();

    if(bool)
    response.sendRe direct("main.js p");

    else
    response.sendRe direct("main.js p");


    %>
    -------------------------------------------

    plz do reply to it to solve my problem.

    thanks
  • BigDaddyLH
    Recognized Expert Top Contributor
    • Dec 2007
    • 1216

    #2
    First off, please help out the forum members who try to read your code:
    1. Use code tags.
    2. Try not to put so many blanks lines in source code -- saves on scrolling.

    I'm not a EJB programmer (I hear EJB is well on the way out, but that's another thread) but you seem to have a basic syntax problem:

    [CODE=Java]VerifyUser vs=userHome.cre ate();
    Boolean b=vs.Verify(use rname,password) ;[/CODE]
    (I should have made a point #3: if you have an error message referring to line #42, please indicate which is line #42!)

    I checked your interface VerifyUser and found:
    [CODE=Java]public boolean Verify(String user, String pswd) throws RemoteException ;[/CODE]
    Do you see the problem and the solution, now?

    I could even add a point #4: the less Java you embed in a JSP the better, and the best is no Java at all. That way, among other things, you don't get these Java errors when compiling JSP.

    Comment

    • star111792
      New Member
      • Jan 2007
      • 26

      #3
      im unable to understand ur view-point. will u kindly elaborate???

      Comment

      • BigDaddyLH
        Recognized Expert Top Contributor
        • Dec 2007
        • 1216

        #4
        [CODE=Java]VerifyUser vs=userHome.cre ate();
        Boolean b=vs.Verify(use rname,password) ;

        ...

        public boolean Verify(String user, String pswd) throws RemoteException ;[/CODE]

        The return type of verify is Boolean, not boolean. Do you know the difference between java.lang.Boole an and boolean?

        Comment

        • star111792
          New Member
          • Jan 2007
          • 26

          #5
          ooooooooooooooo ooooooooooo
          yes i know the difference, this mistake was not intentional. anyways thanks 4 help, but now i m getting another exception. need ur help again

          i m getting the following exception

          [EXCEPTION]

          type Exception report

          message

          description The server encountered an internal error () that prevented it from fulfilling this request.

          exception

          javax.servlet.S ervletException : VerifyUser not bound
          org.apache.jasp er.runtime.Page ContextImpl.doH andlePageExcept ion(PageContext Impl.java:848)
          org.apache.jasp er.runtime.Page ContextImpl.han dlePageExceptio n(PageContextIm pl.java:781)
          org.apache.jsp. Verify_jsp._jsp Service(org.apa che.jsp.Verify_ jsp:98)
          org.apache.jasp er.runtime.Http JspBase.service (HttpJspBase.ja va:97)
          javax.servlet.h ttp.HttpServlet .service(HttpSe rvlet.java:810)
          org.apache.jasp er.servlet.JspS ervletWrapper.s ervice(JspServl etWrapper.java: 322)
          org.apache.jasp er.servlet.JspS ervlet.serviceJ spFile(JspServl et.java:314)
          org.apache.jasp er.servlet.JspS ervlet.service( JspServlet.java :264)
          javax.servlet.h ttp.HttpServlet .service(HttpSe rvlet.java:810)
          org.jboss.web.t omcat.filters.R eplyHeaderFilte r.doFilter(Repl yHeaderFilter.j ava:81)


          root cause

          javax.naming.Na meNotFoundExcep tion: VerifyUser not bound
          org.jnp.server. NamingServer.ge tBinding(Naming Server.java:491 )
          org.jnp.server. NamingServer.ge tBinding(Naming Server.java:499 )
          org.jnp.server. NamingServer.ge tObject(NamingS erver.java:505)
          org.jnp.server. NamingServer.lo okup(NamingServ er.java:278)
          org.jnp.interfa ces.NamingConte xt.lookup(Namin gContext.java:6 10)
          org.jnp.interfa ces.NamingConte xt.lookup(Namin gContext.java:5 72)
          javax.naming.In itialContext.lo okup(InitialCon text.java:347)
          org.apache.jsp. Verify_jsp._jsp Service(org.apa che.jsp.Verify_ jsp:67)
          org.apache.jasp er.runtime.Http JspBase.service (HttpJspBase.ja va:97)
          javax.servlet.h ttp.HttpServlet .service(HttpSe rvlet.java:810)
          org.apache.jasp er.servlet.JspS ervletWrapper.s ervice(JspServl etWrapper.java: 322)
          org.apache.jasp er.servlet.JspS ervlet.serviceJ spFile(JspServl et.java:314)
          org.apache.jasp er.servlet.JspS ervlet.service( JspServlet.java :264)
          javax.servlet.h ttp.HttpServlet .service(HttpSe rvlet.java:810)
          org.jboss.web.t omcat.filters.R eplyHeaderFilte r.doFilter(Repl yHeaderFilter.j ava:81)


          note The full stack trace of the root cause is available in the Apache Tomcat/5.5.9 logs.


          --------------------------------------------------------------------------------

          Apache Tomcat/5.5.9

          [/EXCEPTION]



          what have i done wrong now????

          Comment

          • BigDaddyLH
            Recognized Expert Top Contributor
            • Dec 2007
            • 1216

            #6
            Someone else will have to help you. That looks like an EJB problem.

            Comment

            • star111792
              New Member
              • Jan 2007
              • 26

              #7
              ok. thanks 4 ur support

              Comment

              Working...