Link to home
Start Free TrialLog in
Avatar of Juggy1
Juggy1

asked on

Urgent: JSP & Servlet problem

Hello All

I am using a servlet to create a means of entry to web site, basically a Log In. Furthermore incorporate JSP to work with my servlet, thus the JSP is a form with the username and password fields.

Technologies I'm using are:

1. MySQL 3.23.52
2. Tomcat 4.0.4
3. JPadpro (editor to build Java)

The problem is that I'm having is that Tomcat states "servlet is not availbale".

I have set the context in my web.xml file so Tomcat can see it where it is. But I have used various ways of changing it but still the problem occurs (servlet is not available).

Here is the web.xml file:

<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
    "http://java.sun.com/j2ee/dtds/web-app_2.2.dtd">

<web-app>
  <!-- pdn 15 sept 2001: xsql servlet mapping added -->
  <servlet>
    <servlet-name>
      XSQLServlet
    </servlet-name>
    <servlet-class>
      oracle.xml.xsql.XSQLServlet
    </servlet-class>
  </servlet>
 
  <servlet>
    <servlet-name>
      mylogin
    </servlet-name>
    <servlet-class>
      LoginServlet
    </servlet-class>
  </servlet>
 
 
 
 
 
 

  <servlet>
    <servlet-name>
      soaprouter
    </servlet-name>
    <servlet-class>
      oracle.soap.server.http.SOAPServlet
    </servlet-class>
    <!-- location of soapConfig.xml -->
    <init-param>
      <param-name>soapConfig</param-name>
      <param-value>%SOAP_HOME%/admin/soapConfig.xml</param-value>
    </init-param>
    <!-- SOAP installation directory -->
    <init-param>
      <param-name>soapHome</param-name>
      <param-value>%SOAP_HOME%</param-value>
    </init-param>
  </servlet>
  <servlet-mapping>
    <servlet-name>
      XSQLServlet
    </servlet-name>
    <url-pattern>
      *.xsql
    </url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>
      mylogin
    </servlet-name>
    <url-pattern>
      */servlet/
    </url-pattern>
  </servlet-mapping>
  <!-- remove the servlet-mapping entry for Tomcat -->        
  <servlet-mapping>
    <servlet-name>soaprouter</servlet-name>
    <url-pattern>/soap/servlet/soaprouter</url-pattern>
  </servlet-mapping>
 
  <taglib>
      <taglib-uri>
        petshow-custom-tag-library
      </taglib-uri>
      <taglib-location>
         /WEB-INF/tld/petshow-taglib.tld
      </taglib-location>
  </taglib>
</web-app>

As you can see I have stated the name (mylogin) and class(LoginServlet) of the servlet above in top part of the code. Thus put the mapping underneath the XSQLServlet mapping, giving it a url pattern (*/servlet/).

Please can anyone give some advice or help to this problem, I would be grateful for the help or suggestion in this matter.

Thanks

Regards
Juggy
Avatar of kennethxu
kennethxu

what do you mean by (*/servlet/)? where exactly do you want you servlet map to?

try map to /servlet/LoginServlet
Avatar of Juggy1

ASKER

Thanks for the advice.

I'm still getting same problem:

 The requested resource (/servlet/LoginServlet) is not available

Here is LoginServlet.java code:

package petshowservlets;
import java.sql.*;

import java.io.IOException;
import javax.servlet.*;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.ServletContext;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


public class LoginServlet extends HttpServlet
{
      private String bnDbDriver = "org.gjt.mm.mysql.Driver";
      private String bnDbId = "jdbc:mysql://localhost/itx98jkdb";
      private String bnDbUser = "username";
      private String bnDbPassword = "Password";
      
      
      public void doGet(HttpServletRequest argRequest, HttpServletResponse argResponse) throws ServletException, java.io.IOException
      {
            String targetPage ="/petshow/jsp/Login.jsp";
            
            String UserId = argRequest.getParameter("frmUserId");
            String Password = argRequest.getParameter("frmPassword");
            String test = "ok";
            
            try
            {
                  //***************************************
                  // get the connection
                  //***************************************
                  Class.forName(bnDbDriver);
                  Connection myConnection = DriverManager.getConnection(bnDbId, bnDbUser, bnDbPassword);
                  
                  //***************************************
                  // BUILD SQL QUERY
                  //***************************************
                  String sqlQuery = "SELECT dbAuthorSurName, dbAuthorFirstNames, dbAuthorPassword, dbEmail, dbFaculty, dbJobId FROM Job, Author WHERE dbEmail='" + UserId + "' AND dbAuthorPassword='" + Password + "'";
                  
                  
                  //***************************************
                  // Do the Sql Query
                  //***************************************
                  Statement myStatement = myConnection.createStatement();                        
                  ResultSet myResultSet = myStatement.executeQuery(sqlQuery);
                  
                  myResultSet.first();
                  
                  String dbAuthorSurName = myResultSet.getString("dbAuthorSurName");
                  System.out.println("Author Surname: " + dbAuthorSurName);
                  
                  String dbAuthorFirstNames = myResultSet.getString("dbAuthorFirstNames");
                  System.out.println("Author Firstnames: " + dbAuthorFirstNames);
                  
                  
                  if (!(Password.equals(myResultSet.getString("Password"))))
                  {
                        argRequest.setAttribute("message", "Wrong Password!");      
                        targetPage="/petshow/jsp/ErrorPage.jsp";
                  }
                  
                  argRequest.setAttribute("ASName", myResultSet.getString("dbAuthorSurName"));
                  argRequest.setAttribute("AFNames", myResultSet.getString("dbAuthorFirstNames"));
                  argRequest.setAttribute("AEmail", myResultSet.getString("dbEmail"));
                  argRequest.setAttribute("AType", myResultSet.getString("dbAuthorId"));
                  
            }
            catch(Exception e)
            {
                  System.out.println("LoginServlet.doPost() :" + e);
                  test = "Wrong ID";
                  
                  System.out.println("LoginServlet.doGet(: userId = " + UserId + ", Password = " + Password + ", test = " + test);
                  
                  argRequest.setAttribute("message", "UserId not Found!");
                  targetPage="/petshow/jsp/ErrorPage.jsp";
                  
                  forwardTo(targetPage, argRequest, argResponse);
            }
            
      }
      
      //----------------------------------------------------------------------------
      private void forwardTo(String url, HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException            
      {
            RequestDispatcher myRequestDispatcher;
            myRequestDispatcher = getServletContext().getRequestDispatcher(url);
            myRequestDispatcher.forward(request, response);
      }
      
}


*****************************************************************

Here is the Login.jsp code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<%@ page errorPage="ErrorPage.jsp" %>

<jsp:useBean
      id="myLogIn"
      scope="session"
      class="petshowservlets.LoginServlet"
      />


<jsp:setProperty
      name="myLogIn"
      property="*"
      param="frmUserId"
      />


<jsp:setProperty
      name="myLogIn"
      property="*"
      param="frmPassword"
      />



<html>
      <head>
            <title>LogIn Page</title>
      </head>
      <body>
      <form method="post" action="/servlet/LoginServlet">
            <center>
                  <table cellpadding=4 cellspacing=2 border=0 width="40%">
                        <th bgcolor="#99FF66" colspan=2>
                              <font size=5>LOG IN</font>
                              <font size=1><sup>*</sup> Required Fields</font>
                        </th>
                        
                        <tr bgcolor="#99CC66">
                              <td>
                                    <b>Email<sup>*</sup></b>
                                    <br>
                                    <input type="text" name="frmUserId" size=22 maxlength=50>
                              </td>
                              
                              <td>
                                    <b>Password<sup>*</sup></b>
                                    <br>
                                    <input type="password" name="frmPassword" size=10 maxlength=10>
                              </td>
                        </tr>      
                        
                        <tr bgcolor="#99CC66">
                              <td  align=center colspan="2">
                                    <input type="submit" value="Submit">
                                    <input type="reset"  value="Reset">
                              </td>
                        </tr>
                  </table>
            </form>
      </body>
</html>
      

Maybe the problem is in the code somewhere, I would appreciate it if you can review the code and see where I have gone wrong.

Thanks again for your help.
Juggy
you need full qualified name for your class

 <servlet>
   <servlet-name>
     mylogin
   </servlet-name>
   <servlet-class>
     petshowservlets.petshowservlets
   </servlet-class>
 </servlet>

and your petshowservlets.class should be in WEB-INF/classes/petshowservlets dir.
Avatar of Juggy1

ASKER

Thanks for the advice.

I actually changed the class name towards what you suggested and still the same error in the web browser:

Servlet is not available.

My petshowservlets is in the WEB-INF/classes/petshowservlets dir.

Thanks for the help.
Juggy



I'm sorry type some copy/paste mistabke in my previous post.

your servlet defination was fine:

package petshowservlets;
...
public class LoginServlet extends HttpServlet

complile this and put the LoginServlet.class in WEB-INF/classes/petshowservlets, open a DOS windows to double check all the upper/lower case is correct, don't trust windows explorer.

use this in web.xml:
<servlet>
  <servlet-name>
    mylogin
  </servlet-name>
  <servlet-class>
    petshowservlets.LoginServlet
  </servlet-class>
</servlet>
...
 <servlet-mapping>
   <servlet-name>
     mylogin
   </servlet-name>
   <url-pattern>
     /servlet/LoginServlet
   </url-pattern>
 </servlet-mapping>

restart your server.
Avatar of Juggy1

ASKER

I'm sorry I am not clear in what your trying to say?

I have changed the class: petshowservlets.LoginServlet

and restarted Tomcat and tested still same problem.
Avatar of Juggy1

ASKER

I'm sorry I am not clear in what your trying to say?

Could you please explain again.

I have changed the class: petshowservlets.LoginServlet

and restarted Tomcat and tested still same problem.

Thanks Juggy
did you followed the instruction in my last post?
if you still have problem. please

1. tell us the url on your browser that you try to access your servlet and filesystem directory path to your webapp.

2. check the tomcat console/log and post error message if there is any.
Avatar of Juggy1

ASKER

1. Here is the URL for the filesystem dir path:

http://localhost:8080/yourid

For the servlet:

First it is the Login.jsp
http://localhost:8080/yourid/petshow/jsp/Login.jsp

Secondly the servlet
http://localhost:8080/servlet/LoginServlet

2. The errors in the log:

2003-03-21 20:32:25 Internal Error: File /WEB-INF/web.xml not found
2003-03-21 20:32:25 StandardHost[localhost]: Installing web application at context path  from URL file:C:\j3t\tomcat\webapps\ROOT
2003-03-21 20:32:25 WebappLoader[]: Deploying class repositories to work directory C:\j3t\tomcat\work\Standalone\localhost\_
2003-03-21 20:32:25 StandardManager[]: Seeding random number generator class java.security.SecureRandom
2003-03-21 20:32:25 StandardManager[]: Seeding of random number generator has been completed
2003-03-21 20:32:25 ContextConfig[]: Added certificates -> request attribute Valve
2003-03-21 20:32:25 StandardWrapper[:default]: Loading container servlet default
2003-03-21 20:32:25 default: init
2003-03-21 20:32:25 StandardWrapper[:invoker]: Loading container servlet invoker
2003-03-21 20:32:25 invoker: init






2003-03-21 20:38:00 invoker: Cannot allocate servlet instance for path /servlet/LoginServlet

javax.servlet.ServletException: Wrapper cannot find servlet class LoginServlet or a class it depends on
     at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:873)
     at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:655)



Thanks again
Juggy

>> 2003-03-21 20:32:25 Internal Error: File /WEB-INF/web.xml not found
there is something wrong when you start you tomcat.

>> 1. Here is the URL for the filesystem dir path:
>> http://localhost:8080/yourid

FILESYSTEM means hard disk, e.g. c:\xxx\tomcat\webapps\yyyy. list detail under webapps.
BTW, what is "yourid"? try to access it as http://localhost:8080/yourid/servlet/LoginServlet
Avatar of Juggy1

ASKER

The list under webapps is:

C:/j3t/tomcat/webapps/examples
C:/j3t/tomcat/webapps/tomcat-docs
C:/j3t/tomcat/webapps/manager
C:/j3t/tomcat/webapps/webdav
C:/j3t/tomcat/webapps/ROOT


However, when I create my java classes it is setup in my classes, its like this:

C:/j3t/webappfolder/WEB-INF/classes/petshowservlets




yourid is directory to see petshow where it contains jsp documents in tomcat:

C:/j3t/tomcat/work/Standalone/localhost/yourid/petshow/jsp

Therefore when I type localhost in the url, I need to state yourid as the directory to point to get my petshow and then to jsp.



However, I do have a web.xml files it is not exactly in Tomcat:

C:/j3t/webappfolder/WEB-INF/web.xml

As I stated I store my work in this directory, but I thought  Tomcat would be able to see it.



Avatar of Juggy1

ASKER

1. I have moved my jar files from my webappfolder directory into tomcat's common lib.

C:/j3t/webappfolder/WEB-INF/lib/all my jar files

to

C:/j3t/tomcat/common/lib

2. Started tomcat and in the logs I get this, something is really screwed up:


2003-03-22 15:02:36 WebappLoader[/yourid]: Deploying class repositories to work directory C:\j3t\tomcat\work\Standalone\localhost\yourid
2003-03-22 15:02:36 WebappLoader[/yourid]: Deploy JAR /WEB-INF/lib/cos.jar to c:\j3t\webappfolder\WEB-INF\lib\cos.jar
2003-03-22 15:02:36 WebappLoader[/yourid]: Deploy JAR /WEB-INF/lib/struts.jar to c:\j3t\webappfolder\WEB-INF\lib\struts.jar
2003-03-22 15:02:36 WebappLoader[/yourid]: Deploy JAR /WEB-INF/lib/uploadbean.jar to c:\j3t\webappfolder\WEB-INF\lib\uploadbean.jar
2003-03-22 15:02:36 WebappLoader[/yourid]: Reloading checks are enabled for this Context
2003-03-22 15:02:36 StandardManager[/yourid]: Seeding random number generator class java.security.SecureRandom
2003-03-22 15:02:36 StandardManager[/yourid]: Seeding of random number generator has been completed
2003-03-22 15:02:36 ContextConfig[/yourid]: ContextConfig: Processing START
2003-03-22 15:02:36 StandardContext[/yourid]: Setting deployment descriptor public ID to '-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN'
2003-03-22 15:02:36 StandardContext[/yourid]: Setting deployment descriptor public ID to '-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN'
2003-03-22 15:02:36 ContextConfig[/yourid]: Scanning web.xml tag libraries
2003-03-22 15:02:36 ContextConfig[/yourid]:   URI='petshow-custom-tag-library', ResourcePath='/WEB-INF/tld/petshow-taglib.tld'
2003-03-22 15:02:36 ContextConfig[/yourid]:     tldConfigJar(/WEB-INF/tld/petshow-taglib.tld): java.io.IOException: The system cannot find the path specified
2003-03-22 15:02:36 ContextConfig[/yourid]: Scanning TLD files in /WEB-INF
2003-03-22 15:02:36 ContextConfig[/yourid]: Scanning library JAR files
2003-03-22 15:02:36 ContextConfig[/yourid]:     tldConfigJar(/WEB-INF/lib/cos.jar): java.io.IOException: The system cannot find the path specified
2003-03-22 15:02:36 ContextConfig[/yourid]:     tldConfigJar(/WEB-INF/lib/struts.jar): java.io.IOException: The system cannot find the path specified
2003-03-22 15:02:37 ContextConfig[/yourid]:     tldConfigJar(/WEB-INF/lib/uploadbean.jar): java.io.IOException: The system cannot find the path specified
2003-03-22 15:02:37 ContextConfig[/yourid]: Added certificates -> request attribute Valve
2003-03-22 15:02:37 ContextConfig[/yourid]: Pipline Configuration:
2003-03-22 15:02:37 ContextConfig[/yourid]:   org.apache.catalina.valves.CertificatesValve/1.0
2003-03-22 15:02:37 ContextConfig[/yourid]:   org.apache.catalina.core.StandardContextValve/1.0
2003-03-22 15:02:37 ContextConfig[/yourid]: ======================
2003-03-22 15:02:37 StandardContext[/yourid]: Configuring application event listeners
2003-03-22 15:02:37 StandardContext[/yourid]: Sending application start events
2003-03-22 15:02:37 StandardContext[/yourid]: Starting filters
2003-03-22 15:02:37 StandardContext[/yourid]: Posting standard context attributes
2003-03-22 15:02:37 StandardWrapper[/yourid:default]: Loading container servlet default
2003-03-22 15:02:37 default: init
2003-03-22 15:02:37 StandardWrapper[/yourid:invoker]: Loading container servlet invoker
2003-03-22 15:02:37 invoker: init
2003-03-22 15:02:37 jsp: init
2003-03-22 15:02:37 StandardContext[/yourid]: Starting completed
2003-03-22 15:02:38 WebappLoader[/xsql]: Deploying class repositories to work directory C:\j3t\tomcat\work\Standalone\localhost\xsql
2003-03-22 15:02:38 StandardManager[/xsql]: Seeding random number generator class java.security.SecureRandom
2003-03-22 15:02:38 StandardManager[/xsql]: Seeding of random number generator has been completed
2003-03-22 15:02:38 ContextConfig[/xsql]: Missing application web.xml, using defaults only
2003-03-22 15:02:38 ContextConfig[/xsql]: Added certificates -> request attribute Valve
2003-03-22 15:02:38 StandardWrapper[/xsql:default]: Loading container servlet default
2003-03-22 15:02:38 default: init
2003-03-22 15:02:38 StandardWrapper[/xsql:invoker]: Loading container servlet invoker
2003-03-22 15:02:38 invoker: init
2003-03-22 15:02:38 jsp: init
2003-03-22 15:02:38 Internal Error: File /WEB-INF/web.xml not found
2003-03-22 15:02:38 StandardHost[localhost]: Installing web application at context path  from URL file:C:\j3t\tomcat\webapps\ROOT
2003-03-22 15:02:38 WebappLoader[]: Deploying class repositories to work directory C:\j3t\tomcat\work\Standalone\localhost\_
2003-03-22 15:02:38 StandardManager[]: Seeding random number generator class java.security.SecureRandom
2003-03-22 15:02:38 StandardManager[]: Seeding of random number generator has been completed

Thanks again for your help.
Juggy
ASKER CERTIFIED SOLUTION
Avatar of kennethxu
kennethxu

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Juggy1

ASKER

Thanks for the response..

I see the problem very clearly now, I had got the software from University and one of my lecturers gave document on its installation for home use and configued Tomcat.

How would I configure it, here is the script my lecturer (it was in the server.xml) did:

<!--  pdn/rbc 9 sept 2002 yourid Context added
  -->
  <Context path="/yourid" docBase="c:/j3t/webappfolder" debug="99" privileged="false" reloadable="true" crossContext="false" />
- <!--  pdn/rbc 10 sept 2002 xsql Context added
  -->
  <Context path="/xsql" docBase="c:/j3t/xsql/xdk" debug="0" privileged="false" reloadable="false" crossContext="false" />


They have Tomcat at uni as well, but I would like to keep this the same as I got it at uni, so there is little changes I have to make when I transfer the work to the uni network.

Thanks again
Juggy
right, that's what I mean you need to configure the tomcat's server.xml. glad to know your problem is solved.
Avatar of Juggy1

ASKER

You have been very helpful and I have learned from the responses you had given me.

Thanks again
Juggy
Avatar of Juggy1

ASKER

In my previous email I was talking about my lecturer he had given the documents on installing Tomcat and so on.

I'm sorry if I confused you in some way, however, I have awarded you the points because I see where there problem is.

In the server.xml how would I get it to recognise:

c:/j3t/webappfolder

As you can see in my previous message there is a context written by one of my lecturers, but as you know and I do its not working properly, how could I rectify this?

I would be grateful if you could provide any assistance at all.

Thanks again
Juggy
thanks for your points.

>> I would be grateful if you could provide any assistance at all.
I'm here to help :)

so what's the error message you are getting now?

you shoud add the line right before </Host> in server.xml file.
Avatar of Juggy1

ASKER

I'm not worrying about servlets anymore, Its a scew up in the web.xml on my home PC.

Anyway I have just posted a comment in the question about redirecting JSP, Bobbit31 is helping me out.
I wondered if you can take a look, I think I need a third person it just something minor to do.

response.redirect its not going to a error jsp page if a person exists in the DB.

Thanks again for your help.
Juggy
is your problem in another question solved? I saw bobbit was working hard on it :)

if not, can you zip up your web app and send it to me, kennethxu at hotmail.com, so I can test it out.