Where do I Place my Servlets, JSP and Bean in the Tomcat Server?

I have 3 Files, One JSP which uses a bean and the bean is in classes/com/ch/UserInfobean.class.

I have a Servlet and in the JSP where should I put the Servlet Class File and How should I map it to the JSP in the action tag of the Form.

I have placed in all places and it says " Cannot find the Servlet"?

Please Help.

RajeshPDAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

fargoCommented:
Hii,

I think, u forgot to map it in the web.xml (if tomcat is app server).

  <servlet>
    <servlet-name>YourServlet</servlet-name>
    <servlet-class>com.ch.YourServlet</servlet-class>
  </servlet>

and specify whatever mapping u want..

  <servlet-mapping>
        <servlet-name>YourServlet</servlet-name>
        <url-pattern>/YourServlet</url-pattern>
  </servlet-mapping>

Now u can use directly the name YourServlet for the action.

Hope this helps
regards
fargo

kennethxuCommented:
you should put your servlet under:
youwebapp/WEB-INF/classes/your/servlet/packege/YourSevlet.class
RajeshPDAuthor Commented:
Hi Fargo

I did the same thing as u told me and in action only the FormServlet. But it gave an error like this:

type Status report

message /examples/jsp/FormServlet

description The requested resource (/examples/jsp/FormServlet) is not available.

Pls advice.


in Web.xml

<servlet>
    <servlet-name>FormServlet</servlet-name>
    <servlet-class>com.ch.FormServlet</servlet-class>
  </servlet>


  <servlet-mapping>
        <servlet-name>FormServlet</servlet-name>
        <url-pattern>/FormServlet</url-pattern>
  </servlet-mapping>
Become a CompTIA Certified Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

kennethxuCommented:
according to your defination in web.xml, you should be accessing your servlet as /examples/FormServlet.

if you wish to access it via /examples/jsp/FormServlet, then use /jsp/FormServlet as url-pattern in web.xml

HTH
RajeshPDAuthor Commented:
Still giving me the same Error.
description The requested resource (/examples/jsp/FormServlet) is not available.


Sometimes, my localhost:8080 does not show the default page and does not start. I need to re start the server every time. Any advice?

When I place the above in the XML , I get an exception in the Command prompt.
RajeshPDAuthor Commented:
Can u suggest me any site where they show me how to do all these properly?
RajeshPDAuthor Commented:
Can U gimme an example which uses Form Fields , JSP, Servlets and Beans?
kennethxuCommented:
>>When I place the above in the XML , I get an exception in the Command prompt.
can you post your web.xml

probably you should get a servlet/jsp book to study.
vk33Commented:
Hi!

Don't forget to restart Tomcat as soon as you change anything concerning servlets: recompiling, replacing, modifying web.xml.

I hope it helps...

Regards!
RajeshPDAuthor Commented:
Hi
Error:

description The requested resource (/examples/FormServlet) is not available.


I am attaching all the Files for your Ref:(Not the Bean)

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

<!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>

    <display-name>Tomcat Examples</display-name>
    <description>
      Tomcat Example servlets and JSP pages.
    </description>

    <!-- Define servlet-mapped and path-mapped example filters -->
    <filter>
        <filter-name>Servlet Mapped Filter</filter-name>
        <filter-class>filters.ExampleFilter</filter-class>
      <init-param>
          <param-name>attribute</param-name>
          <param-value>filters.ExampleFilter.SERVLET_MAPPED</param-value>
      </init-param>
    </filter>
    <filter>
        <filter-name>Path Mapped Filter</filter-name>
        <filter-class>filters.ExampleFilter</filter-class>
      <init-param>
          <param-name>attribute</param-name>
          <param-value>filters.ExampleFilter.PATH_MAPPED</param-value>
      </init-param>
    </filter>
    <filter>
        <filter-name>Request Dumper Filter</filter-name>
        <filter-class>filters.RequestDumperFilter</filter-class>
    </filter>

    <!-- Example filter to set character encoding on each request -->
    <filter>
        <filter-name>Set Character Encoding</filter-name>
        <filter-class>filters.SetCharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>EUC_JP</param-value>
        </init-param>
    </filter>

    <filter>
        <filter-name>Compression Filter</filter-name>
        <filter-class>compressionFilters.CompressionFilter</filter-class>

        <init-param>
          <param-name>compressionThreshold</param-name>
          <param-value>10</param-value>
        </init-param>
        <init-param>
          <param-name>debug</param-name>
          <param-value>0</param-value>
        </init-param>
    </filter>

    <!-- Define filter mappings for the defined filters -->
    <filter-mapping>
        <filter-name>Servlet Mapped Filter</filter-name>
      <servlet-name>invoker</servlet-name>
    </filter-mapping>
    <filter-mapping>
        <filter-name>Path Mapped Filter</filter-name>
      <url-pattern>/servlet/*</url-pattern>
    </filter-mapping>


<!-- Example filter mapping to apply the "Set Character Encoding" filter
     to *all* requests processed by this web application -->
<!--
    <filter-mapping>
        <filter-name>Set Character Encoding</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
-->

<!--
    <filter-mapping>
      <filter-name>Compression Filter</filter-name>
      <url-pattern>/CompressionTest</url-pattern>
    </filter-mapping>
-->

<!--
    <filter-mapping>
        <filter-name>Request Dumper Filter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
-->

    <!-- Define example application events listeners -->
    <listener>
        <listener-class>listeners.ContextListener</listener-class>
    </listener>
    <listener>
        <listener-class>listeners.SessionListener</listener-class>
    </listener>

    <!-- Define servlets that are included in the example application -->

    <servlet>
        <servlet-name>SendMailServlet</servlet-name>
        <servlet-class>SendMailServlet</servlet-class>
    </servlet>

    <servlet>
        <servlet-name>
            snoop
        </servlet-name>
        <servlet-class>
            SnoopServlet
        </servlet-class>
<!--
        <init-param>
            <param-name>foo</param-name>
            <param-value>bar</param-value>
        </init-param>
-->
        <run-as>
            <description>Security role for anonymous access</description>
            <role-name>tomcat</role-name>
        </run-as>
    </servlet>

    <servlet>
      <servlet-name>
          servletToJsp
      </servlet-name>
      <servlet-class>
          servletToJsp
      </servlet-class>
    </servlet>
       <servlet>
      <servlet-name>
          FormServlet
      </servlet-name>
      <servlet-class>
          FormServlet
      </servlet-class>
    </servlet>
        <servlet>
        <servlet-name>
            CompressionFilterTestServlet
        </servlet-name>
        <servlet-class>
            compressionFilters.CompressionFilterTestServlet
        </servlet-class>

    </servlet>

    <servlet-mapping>
        <servlet-name>invoker</servlet-name>
        <url-pattern>/servlet/*</url-pattern>
    </servlet-mapping>

    <servlet-mapping>
        <servlet-name>
            CompressionFilterTestServlet
        </servlet-name>
        <url-pattern>
            /CompressionTest
        </url-pattern>
    </servlet-mapping>

    <servlet-mapping>
        <servlet-name>SendMailServlet</servlet-name>
        <url-pattern>/SendMailServlet</url-pattern>
    </servlet-mapping>

    <servlet-mapping>
        <servlet-name>
            snoop
        </servlet-name>
        <url-pattern>
            /snoop
        </url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>
            servletToJsp
        </servlet-name>
        <url-pattern>
            /servletToJsp
        </url-pattern>
    </servlet-mapping>

      

    <taglib>
        <taglib-uri>
         http://jakarta.apache.org/tomcat/debug-taglib
        </taglib-uri>
        <taglib-location>
           /WEB-INF/jsp/debug-taglib.tld
        </taglib-location>
    </taglib>

    <taglib>
        <taglib-uri>
         http://jakarta.apache.org/tomcat/examples-taglib
        </taglib-uri>
        <taglib-location>
           /WEB-INF/jsp/example-taglib.tld
        </taglib-location>
    </taglib>

    <resource-ref>
      <res-ref-name>mail/Session</res-ref-name>
      <res-type>javax.mail.Session</res-type>
      <res-auth>Container</res-auth>
    </resource-ref>

    <security-constraint>
      <display-name>Example Security Constraint</display-name>
      <web-resource-collection>
         <web-resource-name>Protected Area</web-resource-name>
       <!-- Define the context-relative URL(s) to be protected -->
         <url-pattern>/jsp/security/protected/*</url-pattern>
       <!-- If you list http methods, only those methods are protected -->
       <http-method>DELETE</http-method>
         <http-method>GET</http-method>
         <http-method>POST</http-method>
       <http-method>PUT</http-method>
      </web-resource-collection>
      <auth-constraint>
         <!-- Anyone with one of the listed roles may access this area -->
         <role-name>tomcat</role-name>
       <role-name>role1</role-name>
      </auth-constraint>
    </security-constraint>

    <!-- Default login configuration uses form-based authentication -->
    <login-config>
      <auth-method>FORM</auth-method>
      <realm-name>Example Form-Based Authentication Area</realm-name>
      <form-login-config>
        <form-login-page>/jsp/security/protected/login.jsp</form-login-page>
        <form-error-page>/jsp/security/protected/error.jsp</form-error-page>
      </form-login-config>
    </login-config>

    <!-- Security roles referenced by this web application -->
    <security-role>
      <role-name>role1</role-name>
    </security-role>
    <security-role>
      <role-name>tomcat</role-name>
    </security-role>

    <!-- Environment entry examples -->
    <!--env-entry>
      <env-entry-description>
         The maximum number of tax exemptions allowed to be set.
      </env-entry-description>
      <env-entry-name>maxExemptions</env-entry-name>
      <env-entry-value>15</env-entry-value>
      <env-entry-type>java.lang.Integer</env-entry-type>
    </env-entry-->
    <env-entry>
      <env-entry-name>minExemptions</env-entry-name>
      <env-entry-value>1</env-entry-value>
      <env-entry-type>java.lang.Integer</env-entry-type>
    </env-entry>
    <env-entry>
      <env-entry-name>foo/name1</env-entry-name>
      <env-entry-value>value1</env-entry-value>
      <env-entry-type>java.lang.String</env-entry-type>
    </env-entry>
    <env-entry>
      <env-entry-name>foo/bar/name2</env-entry-name>
      <env-entry-value>true</env-entry-value>
      <env-entry-type>java.lang.Boolean</env-entry-type>
    </env-entry>
    <env-entry>
      <env-entry-name>name3</env-entry-name>
      <env-entry-value>1</env-entry-value>
      <env-entry-type>java.lang.Integer</env-entry-type>
    </env-entry>
    <env-entry>
      <env-entry-name>foo/name4</env-entry-name>
      <env-entry-value>10</env-entry-value>
      <env-entry-type>java.lang.Integer</env-entry-type>
    </env-entry>

    <!-- EJB Reference -->
    <ejb-ref>
      <description>Example EJB Reference</description>
      <ejb-ref-name>ejb/Account</ejb-ref-name>
      <ejb-ref-type>Entity</ejb-ref-type>
      <home>com.mycompany.mypackage.AccountHome</home>
      <remote>com.mycompany.mypackage.Account</remote>
    </ejb-ref>

    <!-- Local EJB Reference -->
    <ejb-local-ref>
      <description>Example Local EJB Reference</description>
      <ejb-ref-name>ejb/ProcessOrder</ejb-ref-name>
      <ejb-ref-type>Session</ejb-ref-type>
      <local-home>com.mycompany.mypackage.ProcessOrderHome</local-home>
      <local>com.mycompany.mypackage.ProcessOrder</local>
    </ejb-local-ref>
      
      </web-app>







<jsp:useBean id="form" class ="com.ch.FormBean">
<jsp:setProperty name="form" property="*"/>
</jsp:useBean>

<html>
<body>
<%
String[] errors = (String[])request.getAttribute("errors");
if(errors!=null && errors.length>0)
{
      %>

      <b>Please correct the following Errors:</b>
      <ul>
      <%
            for(int i=0;i<errors.length;i++)
      {%>
            <li><%=errors[i]%></li>
            <%}%>

            </ul>
            <%}%>


            <form action="FormServlet" method="post">
            <INPUT TYPE="text" NAME="name" value ="<jsp:getProperty name="form" property="name"/>">
            <b>Name</b>(Last,First)<br>

            <INPUT TYPE="text" NAME="email" value ="<jsp:getProperty name="form" property="email"/>">
            <b>EMail</b>(user@host)<br>

            <INPUT TYPE="text" NAME="ssn" value ="<jsp:getProperty name="form" property="ssn"/>">
            <b>SSN</b>(123456789)<br>
            <p>
            <INPUT TYPE="submit" value="Submit Form">
            </form>
            </body>
            </html>

Servlet is in:
C:\jakarta-tomcat-4.1.27\jakarta-tomcat-4.1.27\webapps\examples\WEB-INF\classes


Bean is in:
C:\jakarta-tomcat-4.1.27\jakarta-tomcat-4.1.27\webapps\examples\WEB-INF\classes\com\ch


Please let me know whats wrong.

Rajesh.


version of Java:

C:\j2sdkee1.2.1
C:\jdk1.3.1_04
kennethxuCommented:
you don't have servlet mapping in your web.xml. you need this:
 <servlet-mapping>
        <servlet-name>FormServlet</servlet-name>
        <url-pattern>/jsp/FormServlet</url-pattern>
  </servlet-mapping>

and restart your tomcat.
RajeshPDAuthor Commented:
Hi

The above problem is fixed ..Thanks.
Now I have the First page, when i click on submit, it should say Loading in the second page for 5 mins and automatically control transfers to my third page after 5 Mins. How do i do this using JSP?

kennethxuCommented:
>> The above problem is fixed ..Thanks.
It's EE's policy that usually you should close the question when your initial problem is fixed.

>> automatically control transfers to my third page after 5 Mins
you can simply use meta tag in html <head> section
<META HTTP-EQUIV=Refresh CONTENT="300; URL=page3.jsp">
or use:
<% response.setHeader( "Refresh", "300; URL=page3.jsp" ); %>

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JSP

From novice to tech pro — start learning today.