Running a servlet code in Tomcat 4.1 or higher

MY HTML CODE THAT CALLS THE SERVLET:
<html>
<body>
<form method="post"action="http://localhost:1234/examples/servlets/program">
Name : <input type=text name="text1"><br><br><br>
<input type="submit">
</form>
</body>
</html>
MY SERVLET CODE THAT I HAVE ALREADY SUCCESSFULY EXECUTED ON TOMCAT 3.2.1:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class program extends HttpServlet
public void service(HttpServletRequest
req,HttpServletResponse res)throws
IOException,ServletException
PrintWriter out= res.getWriter();
out.println("Hello World!");
String str= req.getParameter("text1");
out.println("WElcome:"+str);
out.close();
Please tell me the exact class paths to set or any batch file to be made,where to save the servlet and html codes.Also do i need to write any other to execute the above servlet in tomcat 4.1 or higher i.e any xml file etc and if yes then please let me know the code and where to save it.
Please also verify the method of executing this servlet.

http://forum.java.sun.com/thread.jspa?threadID=5237132&tstart=15

Similar Messages

  • Running a servlet code over Tomcat 4.1

    MY HTML CODE THAT CALLS THE SERVLET:
    <html>
    <body>
    <form method="post"action="http://localhost:1234/examples/servlets/program">
    Name : <input type=text name="text1">
    <input type="submit">
    </form>
    </body>
    </html>
    MY SERVLET CODE THAT I HAVE ALREADY SUCCESSFULY EXECUTED ON TOMCAT 3.2.1:
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class program extends HttpServlet
    public void service(HttpServletRequest
    req,HttpServletResponse res)throws
    IOException,ServletException
    PrintWriter out= res.getWriter();
    out.println("Hello World!");
    String str= req.getParameter("text1");
    out.println("WElcome:"+str);
    out.close();
    1.==>Any body please tell what all classpaths I have to set here?
    2.==>Do I need to write any xml file for running this code ..if yes then please tell what to write in the xml code and where to save it.
    3.==>Please tell me where to save my servlet code and html code in Tomcat 4.1
    4.==> Do I need any batch file during its execution and lastly how to execute it in Tomcat 4.1...
    I have already successfully executed the program in Tomcat 3.2.1
    5==> Please check if my codes are OK to run over Tomcat 4.1

    You should get in the habit of creating war files ( Web Archive file ).
    You can deploy a war file to any servlet container like tomcat.
    Maven2 is a nice tool that helps you build war files.
    Here is an article on how to get started.
    http://www.javaworld.com/javaworld/jw-12-2005/jw-1205-maven.html

  • How does one set databse parameters in Tomcat to run a servlet?

    Hi, I am trying to run a applet-servlet code, downloaded from the web. According to the installation instructions, the following is stated:
    Database Parameters. You can provide different database parameters to the servlet. These parameters are set during the administration of the servlet.
    dbDriver - name of the database driver class name (default = sun.jdbc.odbc.JdbcOdbcDriver)
    dbURL - complete database URL (default = jdbc:odbc:StudentDatabase)
    userid - user id (default = <none>)
    passwd - password (default = <none>)
    I am running TOMCAT on a Windows2000 machine. My question is how to does one set the parameters in TOMCAT. What is the default userid and password for TOMCAT.
    Any help/advise is appreciated in advance. Thanks.Regards.

    May be parameters must be set in web.xml in your war

  • How to run a servlet in tomcat 5.5

    Hi,iam new to servlets,please help me regarding running a servlet in tomcat 5.5,
    I just want an example servlet to run first,
    the below is the code for the same :-
    //ExampleServlet.java
    package sig;
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class ExampleServlet extends HttpServlet {
         public void init(ServletConfig config) throws ServletException{
              super.init(config);
         public void service(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException{
              PrintWriter out = res.getWriter();
              out.println("<HTML>");
              out.println("<BODY>");
              out.println("<p>Hello World</p>");
              out.println("</BODY>");
              out.println("</HTML>");
    I have created a new folder named "SignatureServlet" under the "webapps" folder of tomcat and have created a "WEB-1NF" folder under it,
    again i have kept my "ExampleServlet.class" inside the "WEB-1NF->classes" folder and the entries for my servlet in the "web.xml" file are:-
    <servlet>
    <servlet-name>ExampleServlet</servlet-name>
    <servlet-class>ExampleServlet</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>ExampleServlet</servlet-name>
    <url-pattern>/ExampleServlet</url-pattern>
    </servlet-mapping>
    still when iam trying to access the servlet using "http://localhost:8080/ExampleServlet/"
    iam getting a HTTP:404 error
    The requested resource () is not available.,
    please help

    You better ask this on a Tomcat forum...
    Timo

  • How to run a servlet in Tomcat 5.0 server

    HI Everybody,
    I want to know how to run the servlet file on my tomcat 5.0 server. that is where to place a class file and deployment details.
    Thanks In ADVANCE

    Sourav_cs wrote:
    I am a biginner to start servlet i get confusion to configure servlet in tomcat 5 where it should be saved in tomcat directory and how to execute that as first timeHi,
    goto
    tomcat 5.0\webappsnow create a folder here. this is your webapplication project name. Let's suppose it as "TestApp"
    inside this create directories as follows :
    TestApp
            |
            |-----JSP/htmls( if you have any )
            |
            |-----WEB-INF(File Folder)
                       |
                       |-----web.xml
                       |-----lib ( Directory. place all the .jar files which are required for this project(if any) )
                       |-----classes ( .class files. )[all of your java code should be placed here.](servlets / beans/ pojo )this is the general Directory structure of a web application. now you've to place the compiled .class file of your servlet in the "TestApp\WEB-INF\classes" directory. make sure that you've configured the servlet in Deploment Desctiptor, i.e, web.xml.
    now start the server and type the url like : "http://localhost:8080/TestApp/TestServlet"
    the port no. 8080 is the default port no. of tomcat. you have to give your port no. if u've modified it. and TestServlet is the <url-pattern> of your servlet.
    go through some tutorials .. then you can easily know that
    Diablo

  • Need basic info how to run my servlet with SSL/http (I am using Tomcat 4.0.

    I have a servlet that gets a user id and password
    and query information from an HTML form
    and then writes back the answer to the query as a new web page. We want to
    make the transaction secure because it is customer confidential information.
    What do I need to do in my servlet to get it to run under SSL?
    (I am using Apache Tomcat 4.0 on WinNT and
    can use either JDK 1.2.2 or 1.3.1....)
    I know this is a very basic question, but what I'm reading does not
    make it clear to me what I have to do to my servlet code to use SSL, or
    whether the server and client do all the work "outside" my
    servlet code so that no changes to the servlet would be required(???).
    Can I use Tomcat 4.0 for SSL? Any help getting my head pointed in the right
    direction will be much appreciated. (You may reply to this forum or
    to my email: [email protected]
    Much thanks!

    When one follows this how-to, one got the following result:
    The same page, say xyz.html, can be accessed in two ways: one is from
    http://localhost:8080/xyz.html, and the other is from https://localhost:8443/xyz.html.
    How can one allow people to be only able to access from https://localhost:8443/xyz.html, to be not able to access from http://localhost:8080/xyz.html? There is one sentence mentioned some where that Servlet 2.4 specification can do this. But Servlet 2.4 specification would not provide any help. Any clue?

  • How to run a servlet in tomcat 5.0.

    Hi all,
    how to run a servlet in tomcat 5.0
    please tell me the entire procedure....(directory structure)
    step by step....

    hi :-)
    http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/Servlets.html
    or
    http://www.google.com.ph/search?hl=en&q=java+servlet+tutorial&btnG=Google+Search&meta=
    regards,

  • Cannot run a servlet using Tomcat. Urgent

    I have a webapplication which uses some jsp's and servlets. The jsp pages work fine when I use
    http://hostname:8080/MyWebapp/Filename.jsp
    However, when I developed a java servlet and put the class file in WEB-INF/classes directory of my web application and tried to access it.
    I got a resource not found error.
    The strange thing is that when I put the file in the web-inf/classes folder of examples webapplication (which comes with Tomcat) I am able to run the servlet using
    http://hostname:8080/examples/servlet/Class file
    I am not sure what is wrong.
    Can someone help me.
    Thanks in advance
    Vamsi.

    It's predictable. The Servlet and JSP specifications mandate that you cannot directly access resources under WEB-INF directory. You have to set up servlet mapping configuration in your web.xml to specify how to access the resources, both Servlet and JSP, there.
    When you copied your files in a demo webapp of Tomcat, the web.xml of the demo app already set up the mapping like following for you. So you could use http://hostname:8080/examples/servlet/Class to visit the servlet.
    <servlet-mapping>
    <servlet-name>invoker</servlet-name>
    <url-pattern>/servlet/*</url-pattern>
    </servlet-mapping>
    The default setting since Tomcat 4.1 turned off servlet invoker in web.xml under conf directory. You can uncomment the above lines in this file to turn it on. Then you are able to visit your servlet without <servlet-mapping> configured using the following syntax,
    http://hostname:8080/<your_app_name>/servlet/<your_servlet_name>

  • How to run a servlet in tomcat

    how i can run a servlet in tomcat?

    how i can run a servlet in tomcat?Don't try to do that yet; in your other thread you have shown that your are
    not capable yet of setting up a proper development environment.
    Take my advice, you can't walk or run yet so start with the basics.
    kind regards,
    Jos

  • Tomcat error while trying to run the servlet

    I am etting the below error while trying to run a servlet from tomcat server.
    HTTP Status 404 - /servlet/DailyStatusServlet
    type Status report
    message /servlet/DailyStatusServlet
    description The requested resource (/servlet/DailyStatusServlet) is not available.
    Can anyone help me in solving this error.

    rnaaz wrote:
    Can anyone help me in solving this error.Start by making sure you've properly mapped that URL in your deployment descriptor (web.xml file).
    ~

  • Can I run the Servlet and Bean code on Sun ONE Webserver 6.1 SP5

    Hi all.
    My environment as below.
    1) Windows 2000 Server SP4
    2) Sun ONE Webserver 6.1 SP5
    3) JRE1.5.0
    The directory ( WEB-INF/classes) where is to create on. I have a Bean and Servlet code but I can't
    to run it on. Another code Jsp, HTML can run.
    How can I do?

    Your question is somewhat vague, but I'll presume that you are asking how you can invoke your servlets.
    If the servlet classes are correctly deployed, you can invoke them directly. i.e. http://host/<app>/servlet/<classname>. Or, you can create servlet mappings.
    Java beans cannot be invoked the same way a servlet can. You can access beans from within servlets.
    For more details, check out the servlet tutorials at http://java.sun.com

  • Run servlet automatically when tomcat startup

    Dear all
    I need help to run servlet automatically when tomcat startup without starting even the application containing the servlet
    thanks in advance

    lol
    i've the same problem with my car,I want it to go ahead but without starting the engine and using all this gasoline...
    Seriously... the servlet IS almost your application
    when you start the server, the application starts to
    check the init() method of the servlet Interface
    and the "load-on-startup" parameter of the servlet in the deployment descriptor

  • Help needed to run JSTL 1.1 in Tomcat 6.0.16

    Hi All,Help needed to run JSTL 1.1 in Tomcat 6.0.16. I am trying to run the example given in http://tomcat.apache.org/tomcat-6.0-doc/jndi-datasource-examples-howto.html The example tries to connect to MySQL database from JSP using JSTL and JNDI Datasource.I am running the example using Eclipse 3.4.2 using Sysdeo plugin to start and stop Tomcat server from Eclipse IDE.
    My web.xml file has <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
    </web-app>
    and test.jsp has proper taglib directives
    <%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    I have placed the jstl.jar and standard.jarof the jakarta-taglibs-standard-1.1.2.zip under E:\Deepa\workspace\DBTest\WebContent\WEB-INF\lib directory also placedcontext.xml file under E:\Deepa\workspace\DBTest\WebContent\META-INF and the content of context.xml is as below
    <Context path="/DBTest" docBase="DBTest"
    debug="5" reloadable="true" crossContext="true">
    <Resource name="jdbc/TestDB" auth="Container" type="javax.sql.DataSource"
    maxActive="100" maxIdle="30" maxWait="10000"
    username="deepa" password="mysql" driverClassName="com.mysql.jdbc.Driver"
    url="jdbc:mysql://localhost:3306/javatest?autoReconnect=true"/>
    </Context>
    Now while running the example, Eclipse creates one DBTest.xml file under C:\Program Files\Apache Software Foundation\Tomcat 6.0\conf\Catalina\localhost
    which has the following line:
    <Context path="/DBTest" reloadable="true" docBase="E:\Deepa\workspace\DBTest" workDir="E:\Deepa\workspace\DBTest\work" />
    I am getting the following error when running http://localhost/DBTest/WebContent/test.jsp
    in Browser:
    <HTTP Status 500 -
    type Exception report
    message
    description The server encountered an internal error () that prevented it from fulfilling this request.
    exception
    org.apache.jasper.JasperException: The absolute uri: http://java.sun.com/jsp/jstl/sql cannot be resolved in either web.xml or the jar files deployed with this application
    org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:51)
    org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:409)
    org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:116)
    org.apache.jasper.compiler.TagLibraryInfoImpl.generateTLDLocation(TagLibraryInfoImpl.java:315)
    org.apache.jasper.compiler.TagLibraryInfoImpl.<init>(TagLibraryInfoImpl.java:148)
    org.apache.jasper.compiler.Parser.parseTaglibDirective(Parser.java:431)
    org.apache.jasper.compiler.Parser.parseDirective(Parser.java:494)
    org.apache.jasper.compiler.Parser.parseElements(Parser.java:1444)
    org.apache.jasper.compiler.Parser.parse(Parser.java:138)
    org.apache.jasper.compiler.ParserController.doParse(ParserController.java:216)
    org.apache.jasper.compiler.ParserController.parse(ParserController.java:103)
    org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:154)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:315)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:295)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:282)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:586)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    In the Tomcat Server console, I am getting the following error:
    INFO: Server startup in 7295 ms
    May 20, 2009 6:36:48 AM org.apache.jasper.compiler.TldLocationsCache processWebDotXml
    WARNING: Internal Error: File /WEB-INF/web.xml not found
    May 20, 2009 6:36:48 AM org.apache.catalina.core.StandardWrapperValve invoke
    SEVERE: Servlet.service() for servlet jsp threw exception
    org.apache.jasper.JasperException: The absolute uri: http://java.sun.com/jsp/jstl/sql cannot be resolved in either web.xml or the jar files deployed with this application
    what is the problem with my code?
    When running the same example, by creating a local server in Eclipse(creating new Server connection pointing to same Tomcat 6.0 installation) it runs fine without any error.

    Hi evnafets,
    Wow, very helpful information, great insight into working of Eclipse. Thanks a lot.
    I have one more question. I have a context.xml file under {color:#0000ff}E:\Deepa\workspace\DBTest\WebContent\META-INF{color} folder and that has the Resource element to connect to MySQL database:
    {code{color:#000000}}{color}<Context path="/DBTest" docBase="DBTest" debug="5" reloadable="true" crossContext="true">
    <Resource name="jdbc/TestDB" auth="Container" type="javax.sql.DataSource" maxActive="100" maxIdle="30" maxWait="10000" username="deepa" password="mysql" driverClassName="com.mysql.jdbc.Driver"
    {color:#0000ff}url="jdbc:mysql://localhost:3306/javatest?autoReconnect=true"/>{color}
    {color:#0000ff}</Context>{color}As usual when running application in local Tomcat server of Eclipse, this data source works fine. But when I run the application on Tomcat, by starting Sysdeo plugin from Eclipse, the DBTest.xml file created in C:\Tomcat 6.0\conf\Catalina\localhost has the context entry as<Context path="/DBTest" reloadable="true" docBase="E:\Deepa\workspace\DBTest\WebContent" workDir="E:\Deepa\workspace\DBTest\work">
    </Context>The<Resource> element I have specified in the context.xml of \WebContent\META-INF folder is not taken into account by Tomcat and it gives the following error:May 21, 2009 5:20:04 AM org.apache.catalina.core.StandardWrapperValve invoke
    SEVERE: Servlet.service() for servlet jsp threw exception
    javax.servlet.jsp.JspException: Unable to get connection, DataSource invalid: "org.apache.tomcat.dbcp.dbcp.SQLNestedException_: Cannot create JDBC driver of class '' for connect URL 'null'"
    _at org.apache.taglibs.standard.tag.common.sql.QueryTagSupport.getConnection(_QueryTagSupport.java:276_)
    at org.apache.taglibs.standard.tag.common.sql.QueryTagSupport.doStartTag(_QueryTagSupport.java:159_)
    at org.apache.jsp.test_jsp._jspx_meth_sql_005fquery_005f0(_test_jsp.java:113_)
    at org.apache.jsp.test_jsp._jspService(_test_jsp.java:66_)
    at org.apache.jasper.runtime.HttpJspBase.service(_HttpJspBase.java:70_)
    at javax.servlet.http.HttpServlet.service(_HttpServlet.java:717_)
    at org.apache.jasper.servlet.JspServletWrapper.service(_JspServletWrapper.java:374_)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(_JspServlet.java:342_)
    at org.apache.jasper.servlet.JspServlet.service(_JspServlet.java:267_)
    at javax.servlet.http.HttpServlet.service(_HttpServlet.java:717_)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(_ApplicationFilterChain.java:290_)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(_ApplicationFilterChain.java:206_)
    at org.apache.catalina.core.StandardWrapperValve.invoke(_StandardWrapperValve.java:233_)
    at org.apache.catalina.core.StandardContextValve.invoke(_StandardContextValve.java:191_)
    at org.apache.catalina.core.StandardHostValve.invoke(_StandardHostValve.java:128_)
    at org.apache.catalina.valves.ErrorReportValve.invoke(_ErrorReportValve.java:102_)
    at org.apache.catalina.core.StandardEngineValve.invoke(_StandardEngineValve.java:109_)
    at org.apache.catalina.connector.CoyoteAdapter.service(_CoyoteAdapter.java:286_)
    at org.apache.coyote.http11.Http11Processor.process(_Http11Processor.java:845_)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(_Http11Protocol.java:583_)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(_JIoEndpoint.java:447_)
    at java.lang.Thread.run(_Thread.java:619_)
    {code}
    So to overcome this error I had to place the <Resource> element in DBTest.xml under C:\Tomcat 6.0\conf\Catalina\localhost {color:#000000}and then it works fine. {color}{color:#ff0000}*Why is the context.xml file in META-INF not considered by Tomcat server using Sysdeo Plugin?*
    *Thanks,*
    *Deepa*{color}
    {color}
    Edited by: Deepa76 on May 26, 2009 9:32 PM

  • Error While trying to run a servlet

    I am getting the below error while trying to run a servlet using tomcat.In this admin is a directory where I have a html file called admin.html which calls the servlet AdminServlet & replaces the url by /servlet/AdminServlet.
    HTTP Status 404 - /SPOT/admin/servlet/AdminServlet
    type Status report
    message /SPOT/admin/servlet/AdminServlet
    description The requested resource (/SPOT/admin/servlet/AdminServlet) is not available.
    For more details I am also copying the code from the admin.html file below.
    <script language=JavaScript>
    document.location.replace('../servlet/AdminServlet');
    </script>

    JavaScript != javareplace or redirect ??

  • Am getting the following error while running the servlet example

    Hi,
    am getting the following error while running the servlet example
    message
    description The server encountered an internal error () that prevented it from fulfilling this request.
    exception
    java.lang.NullPointerException
         edu.dao.StudentDao.insertStudent(StudentDao.java:18)
         edu.servlet.StudentServlet.doGet(StudentServlet.java:25)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    note The full stack trace of the root cause is available in the Apache Tomcat/5.5.20 logs.
    Thanks
    //sreekanth

    Hi,
    the following code i have written in StudentDao
    package edu.dao;
    import java.sql.Connection;
    import java.sql.PreparedStatement;
    import java.sql.SQLException;
    import org.apache.commons.dbutils.DbUtils;
    import edu.model.Student;
    import edu.util.DBUtil;
    public class StudentDao {
         public void insertStudent(Student student) {
              String stuQuery = "INSERT INTO STUDENT VALUES(?,?)";
              Connection connection = DBUtil.getConnection();
              PreparedStatement preparedStatement = null;
              try {
                   preparedStatement = connection.prepareStatement(stuQuery);
                   preparedStatement.setString(1,student.getStudentNo());
                   preparedStatement.setString(2, student.getStudentName());
                   preparedStatement.executeUpdate();
              } catch(SQLException e){
                   System.out.println("..Sql exception......");
              }finally {
                   DbUtils.closeQuietly(connection,preparedStatement,null);
    }

Maybe you are looking for

  • Can you save a document in Pages and then upload it to a website?

    In other words, can I create a word document in Pages on the iPad and save it somewhere (?) and then go to a site and use its upload feature, ie Browse for a document, and then send it to the site. (Right now, the "Choose File" button on the site I w

  • Adobe Customer Service vs Avid's

    I recently upgraded my Adobe and Avid software suites and was able to make a better comparison between both companies customer service. First, I want to make clear that except for the Creative Cloud membership, I always buy my software from authorize

  • Computer Does not identify password

    My iMac doesn t Want to accept my password although i m sûre to be the good one. I try to change my user name to recreate a new password but it Does Want to take it into account . CAN somebody help me? Thank you

  • Can I email all my numbers spreadsheets in one e mail?

    Can I email all my numbers spreadsheets in one e mail?

  • Finder: annoying repositioning

    Hi all, Already a problem in Mountain Lion and unfortunately still there in Mavericks: Finder will reposition itself somewhere near the end of the file/folder list after expanding or collapsing a folder. This is especially the case when sorting seque