How to run servlet by using main?

How can I use main to run servlet?
I cannot put request and response object into doGet(request, response) method
I want this because I want to run this servlet daily and I plan to put it in cron job
Calvin

Hi
Perhaps you cannot run servlet without using browser. But you can make that program as an application in order to run in Dos or Unix shell.
But still you can run servlet without using browser How?
You can debug servlets with the same jdb commands you use to debug an applet or an application. The JavaTM Servlet Development Kit (JSDK) provides a standalone program
called servletrunner that lets you run a servlet without a web browser. On most systems, this program simply runs the java sun.servlet.http.HttpServer command. You
can, therefore, start a jdb session with the HttpServer class.
A key point to remember when debugging servlets is that Java Web server and servletrunner achieve servlet loading and unloading by not including the servlets directory on
the CLASSPATH. This means the servlets are loaded using a custom classloader and not the default system classloader.
Running servletrunner in Debug Mode
Running Java Web ServerTM in Debug Mode
Running servletrunner in Debug Mode
In this example, the servlets examples directory is included on the CLASSPATH. You can configure the CLASSPATH for debug mode as follows:
Unix
$ export CLASSPATH=./lib/jsdk.jar:./examples:$CLASSPATH
Windows
$ set CLASSPATH=lib\jsdk.jar;examples;%classpath%
To start the servletrunner program you can either run the supplied startup script called servletrunner or just supply the servletrunner classes as a parameter to jdb. This
example uses the parameter to servletrunner.
$ jdb sun.servlet.http.HttpServer
Initializing jdb...
0xee2fa2f8:class(sun.servlet.http.HttpServer)
> stop in SnoopServlet.doGet
Breakpoint set in SnoopServlet.doGet
> run
run sun.servlet.http.HttpServer
running ...
main[1] servletrunner starting with settings:
port = 8080
backlog = 50
max handlers = 100
timeout = 5000
servlet dir = ./examples
document dir = ./examples
servlet propfile = ./examples/servlet.properties
To run SnoopServlet in debug mode, enter the following URL in a browser where yourmachine is the machine where you started servlet runner and 8080 is the port number
displayed in the settings output.
http://yourmachine:8080/servlet/SnoopServlet
In this example jdb stops at the first line of the servlet's doGet method. The browser will wait for a response from your servlet until a timeout is reached.
main[1] SnoopServlet: init
Breakpoint hit: SnoopServlet.doGet (SnoopServlet:45)
Thread-105[1]
We can use the list command to work out where jdb has stopped in the source.
Thread-105[1] list
41 throws ServletException, IOException
42 {
43 PrintWriter out;
44
45 => res.setContentType("text/html");
46 out = res.getWriter ();
47
48 out.println("<html>");
49 out.println("<head>
<title>Snoop Servlet
</title></head>");
Thread-105[1]
The servlet can continue using the cont command.
Thread-105[1] cont
Running Java Web Server in Debug Mode
The JSDK release does not contain classes available in the Java Web server and it also has its own special servlet configuration. If you cannot run your servlet from
servletrunner, then the other option is to run the Java Web server in debug mode.
To do this add the -debug flag for the first parameter after the java program. For example in the script bin/js change the JAVA line to look like the following. In releases prior
to the Java 2 platform release, you will also need to change the program pointed to by the variable $JAVA to java_g instead of java.
Before:
exec $JAVA $THREADS $JITCOMPILER $COMPILER $MS $MX \
After:
exec $JAVA -debug $THREADS $JITCOMPILER
$COMPILER $MS $MX \
Here is how to remotely connect to the Java Web Server. The agent password is generated on the standard output from the Java Web Server so it can be redirected into a file
somewhere. You can find out where by checking the Java Web Server startup scripts.
jdb -host localhost -password <the agent password>
The servlets are loaded by a separate classloader if they are contained in the servlets directory, which is not on the CLASSPATH used when starting the Java Web server.
Unfortunately, when debugging remotely with jdb, you cannot control the custom classloader and request it to load the servlet, so you have to either include the servlets
directory on the CLASSPATH for debugging or load the servlet by requesting it through a web browser and then placing a breakpoint once the servlet has run.
In this next example, the jdc.WebServer.PasswordServlet is included on the CLASSPATH when Java Web server starts. The example sets a breakpoint to stop in the service
method of this servlet, which is the main processing method of this servlet.
The Java Web Server standard output produces this message, which lets you proceed with the remote jdb session:
Agent password=3yg23k
$ jdb -host localhost -password 3yg23k
Initializing jdb...
> stop in jdc.WebServer.PasswordServlet:service
Breakpoint set in jdc.WebServer.PasswordServlet.service
> stop
Current breakpoints set:
jdc.WebServer.PasswordServlet:111
The second stop lists the current breakpoints in this session and shows the line number where the breakpoint is set. You can now call the servlet through your HTML page. In
this example, the servlet is run as a POST operation
<FORM METHOD="post" action="/servlet/PasswordServlet">
<INPUT TYPE=TEXT SIZE=15 Name="user" Value="">
<INPUT TYPE=SUBMIT Name="Submit" Value="Submit">
</FORM>
You get control of the Java Web Server thread when the breakpoint is reached, and you can continue debugging using the same techniques as used in the Remote Debugging
section.
Breakpoint hit: jdc.WebServer.PasswordServlet.service
(PasswordServlet:111) webpageservice Handler[1] where
[1] jdc.WebServer.PasswordServlet.service
(PasswordServlet:111)
[2] javax.servlet.http.HttpServlet.service
(HttpServlet:588)
[3] com.sun.server.ServletState.callService
(ServletState:204)
[4] com.sun.server.ServletManager.callServletService
(ServletManager:940)
[5] com.sun.server.http.InvokerServlet.service
(InvokerServlet:101)
A common problem when using the Java WebServer and other servlet environments is that Exceptions are thrown but are caught and handled outside the scope of your servlet.
The catch command allows you to trap all these exceptions.
webpageservice Handler[1] catch java.io.IOException
webpageservice Handler[1]
Exception: java.io.FileNotFoundException
at com.sun.server.http.FileServlet.sendResponse(
FileServlet.java:153)
at com.sun.server.http.FileServlet.service(
FileServlet.java:114)
at com.sun.server.webserver.FileServlet.service(
FileServlet.java:202)
at javax.servlet.http.HttpServlet.service(
HttpServlet.java:588)
at com.sun.server.ServletManager.callServletService(
ServletManager.java:936)
at com.sun.server.webserver.HttpServiceHandler
.handleRequest(HttpServiceHandler.java:416)
at com.sun.server.webserver.HttpServiceHandler
.handleRequest(HttpServiceHandler.java:246)
at com.sun.server.HandlerThread.run(
HandlerThread.java:154)
This simple example was generated when the file was not found, but this technique can be used for problems with posted data. Remember to use cont to allow the web server
to proceed. To clear this trap use the ignore command.
webpageservice Handler[1] ignore java.io.IOException
webpageservice Handler[1] catch
webpageservice Handler[1]
I hope this will help you.
Thanks
Bakrudeen

Similar Messages

  • How to run servlet in java webserver2.0

    how to configure java webserver2.0 and how to run servlet in that

    Hi Friend,
    Try changing the servlet code to this and just tell wat happens after this.
    and wat can you see on your Browser Screen.
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.sql.*;
    public class login extends HttpServlet {
    public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
    if (req.getParameter("t1") == null || req.getParameter("t2") == null)
    out.println("Enter User Name And Password");
    String uid=req.getParameter("t1");
    String pwd=req.getParameter("t2");
    res.setContentType("text/html");
    PrintWriter out=res.getWriter();
    out.println("<html>"); out.println("<head>");
    out.println("<title>Login</title>"); out.println("</head>");
    out.println("<body>");
    try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    catch(ClassNotFoundException e)
    out.println("<h3>"+e+"</h3>");
    try{
    Connection con=DriverManager.getConnection("jdbc:odbc:ms","scott","tiger");
    PreparedStatement psm=con.prepareStatement("select * from reg where uid1=? and pwd=?");
    psm.setString(1,uid);
    psm.setString(1,pwd);
    ResultSet rs=psm.executeQuery();
    if(rs.next())
    { out.println("<html><head><title>WELCOME</title></head>");
    out.println("<body><b><i>Hello user "+uid+"</b></i>");
    out.println("</body></html>"); }
    else
    res.sendRedirect("http://localhost:8080/login.html");
    } catch(SQLException e)
    { e.printStackTrace();}
    rs.close();
    con.close();
    out.close();
    After this try creating a odbc for oracle database at control panel with the name ms.
    Please inform me wat happens after this and friend do give some information about wat kind of web-server are you using.Because calling of your servlets differs the way your configure your web-server and the default configurations differ from web-server to web-server.
    Regards,
    RAHUL

  • How to Run servlet in Tomcat 5.5.9

    hi
    How to run servlet in tomcat 5.5.9?how to set context path in server.xml of conf folder in tomcat since there is no context tag in server.xml.
    Jiten

    Hi ! I have a similar problem, well, it's along the same line ...
    I'm using NetBeans 4.1, and i've coded a servlet. Using NetBeans to launch my servlet (with the bundled Tomcat 5.5.7) works fine, however i need to deploy my application unto a Tomcat 5.5.9 server.
    Thus, i copied the WAR file generated by NetBeans into the Tomcat 5.5.9 webapps directory, and Tomcat expands it.
    Problem is when i run my JSP pages with the form tags, they do not work on the Tomcat 5.5.9 environment. Anyone knows why?
    (These work on the NetBeans Tomcat bundle 5.5.7)
    My form action :
    <form name="index" method="get" action="PageServlet">
    My web.xml :
    <servlet>
    <servlet-name>PageServlet</servlet-name>
    <servlet-class>application.PageServlet</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>PageServlet</servlet-name>
    <url-pattern>/PageServlet</url-pattern>
    </servlet-mapping>
    I'm really stumbed on why it doesn't work in Tomcat 5.5.9, any help is greatly appreciated, thanks in advance ^_^

  • How to run servlet,jsp in eclipseand to start tomcat in eclipse

    hi
    i want to know how to run servlet and jsp in eclipse 3.0
    and to start tomcat server in same.
    please reply me the steps involved indetail.
    regards
    saravanakumar

    Find Lomboz J2EE plugin and a tutorial of how to use it :)

  • How 2 Run Servlet

    How to run servlet in tomcat5.5?

    Frd...,
    After written the Servlet you shold do the mapping,
    than u will use the Application or Web-Server for the servlet deployment
    In mapping there is the name url pattern. that will be call in the browser.
    But dear u shold go to the Tutorial ..............U will get the Step by Step
    to deploy it.
    saM

  • How to run servlet codes in WebServer 6.1?

    I am new to Java Web Server and at our place we had installed WebServer 6.1. How to run Servlets in this - the default directory is
    http//win2000:81/Sun/WebServer6.1/docs
    I have'nt insatlled any new virtual class / servers - just running with the default class and servers.
    I could not find any virtual directory named servlet (similar to JavaWebServer 2.0) here.
    Someone kindly tell me how to post servlet files and run them.

    Refer "Sun ONE Web Server 6.1 Programmer's Guide to Web Applications"
    http://docs.sun.com/app/docs/doc/817-1833-10
    Meena

  • Urgent - How to Run a FM using CATT script tool,

    Hi All,
    How to Run a FM using CATT script tool,
    Thanks in advance,
    KSR

    choose  type as "Function module test" (if you are in release less than 6.4 abap) after entering into t.code SCAT.
    Pl. refer to this documentation for creating function module test cases
    <a href="http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCCATTOL/CACATTOL.pdf">http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCCATTOL/CACATTOL.pdf</a>
    reward if it helps
    Krishna

  • How to run servlet in weblogic 8.1

    hi!
    i m new to weblogic.how to run servlet in weblogic8.1.i get lot of errors when i compile it in command prompt.but when i do the same thing in tomcat,i dont get errors & it runs successfully.help me out.how to compile servlets in weblogic 8.1.some say i have to create .jar file.pls tell me the procedure.i m new to j2ee.i have installed jdk1.5 .
    pls its urgent

    a lot of error....
    mmmm no sorry, i don't see
    it remembers me when i was dating sarah,it was very difficult... but now i'm dating anne it's really easier... any idea on what was going wrong with sarah?
    ok sorry for this allegory, just tired to ask always the same thing:
    WHAT ERRORS???

  • How to run Servlet in Tomcat 5.5.7 Server

    Hi,
    How to run Servlet in Tomcat 5.5.7 Server. I mean where I should copy my *.class file.
    Thanks in Advance.
    bbye.

    In order to complile the servlet you need to tell java where to find the servlet libary (as stated above by setting the class path). or (much easier IMO)
    copy the servlet-api.jar to
    JavaInstallDirectory\jre\lib\ext

  • How to run servlet,jsp in eclipse software

    can any one tell me how to run servlet ,jsp in eclipse
    and how to start tomcat server in eclipse
    reply me
    regards
    saravana

    Can anybody help me as I wanted to know how to run servlet,jsp in eclipse software...
    If somebody can forward me the screenshots than it would be of great help....
    Thanks

  • How to run servlets in tomcat

    Hi ,
    How to run servlets in tomcat server. I created two files html and servlet file.
    Html file
    callservlet.html
    <html>
    <body>
    <form method=post action="servletcalled.class">
    <input type=submit value="submit">
    </form>
    <body>
    </html>
    servlet file
    servletcalled.java contains
    public void doPost(HttpServletRequest req,HttpServletResponse res ){
    java.io.PrintWriter out = req.getWriter();
    out.println("Hi, executed");
    i put the callservlet.html in webapps/examples/ and servletcalled.class was in webapps/examples/Web-inf/classes/
    After starting the tomcat and running the program html file is getting exceuted but when i click on the submit button this error is prompted
    type Status report
    message servletcalled.class
    description The requested resource (servletcalled.class) is not available.
    Thanks in advance

    Thanks,
    I created a new directory in webapps
    s "webapps/test".
    Test directory contains
    1. callservlet.html file
    2. another directory Web-inf (i.e,
    webapps/test/Web-inf)
    Web-inf directory contains
    1. web.xml file
    2. another directory classes (i.e,
    webapps/test/Web-inf/calsses)
    classes directory contains
    1. servletcalled.class file
    web.xml file contains
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web
    Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd">
    <web-app>
    <servlet>
    <servlet-name>Example</servlet-name>
    <servlet-class>Example</servlet-class>
    </servlet>
    </web-app>
    -->should be: <servlet-class>servletcalled</servlet-called>
    then in the <web-app> scope define this:
    <servlet-mapping>
    <servlet-name>Example</servlet-name>
    <url-pattern>/servlets/Example</url-pattern>
    </servlet-mapping>
    >
    thanks in advance i am working hard on that but
    notable to get the solutionbtw by reading the documentation of tomcat and tutorials of jave on the java site (here), you would have known this!

  • How to run the job using DBMS_SCHEDULER

    How to run the job using DBMS_SCHEDULER
    pleas give some sample Iam very new to DBMS_SCHEDULER

    Hi
    DBMS_SCHEDULER
    In Oracle 10g the DBMS_JOB package is replaced by the DBMS_SCHEDULER package. The DBMS_JOB package is now depricated and in Oracle 10g it's only provided for backward compatibility. From Oracle 10g the DBMS_JOB package should not be used any more, because is could not exist in a future version of Oracle.
    With DBMS_SCHEDULER Oracle procedures and functions can be executed. Also binary and shell-scripts can be scheduled.
    Rights
    If you have DBA rights you can do all the scheduling. For administering job scheduling you need the privileges belonging to the SCHEDULER_ADMIN role. To create and run jobs in your own schedule you need the 'CREATE JOB' privilege.
    With DBMS_JOB you needed to set an initialization parameter to start a job coordinator background process. With Oracle 10g DBMS_SCHEDULER this is not needed any more.
    If you want to user resource plans and/or consumer groups you need to set a system parameter:
    ALTER SYSTEM SET RESOURCE_LIMIT = TRUE;
    Baisc Parts: Job
    A job instructs the scheduler to run a specific program at a specific time on a specific date.
    Programs
    A program contains the code (or reference to the code ) that needs to be run to accomplish a task. It also contains parameters that should be passed to the program at runtime. And it?s an independent object that can referenced by many jobs
    Schedules
    A schedule contains a start date, an optional end date, and repeat interval with these elements; an execution schedule can be calculated.
    Windows
    A window identifies a recurring block of time during which a specific resource plan should be enabled to govern resource allocation for the database.
    Job groups
    A job group is a logical method of classifying jobs with similar characteristics.
    Window groups
    A window groups is a logical method of grouping windows. They simplify the management of windows by allowing the members of the group to be manipulated as one object. Unlike job groups, window groups don?t set default characteristics for windows that belong to the group.
    Using Job Scheduler
    SQL> drop table emp;
    SQL> Create table emp (eno int, esal int);
    SQL > begin
    dbms_scheduler.create_job (
    job_name => 'test_abc',
    job_type => 'PLSQL_BLOCK',
    job_action => 'update emp set esal=esal*10 ;',
    start_date => SYSDATE,
    repeat_interval => 'FREQ=DAILY; INTERVAL=10',
    comments => 'Iam tesing scheduler');
    end;
    PL/SQL procedure successfully completed.
    Verification
    To verify that job was created, the DBA | ALL | USER_SCHEDULER_JOBS view can be queried.
    SQL> select job_name,enabled,run_count from user_scheduler_jobs;
    JOB_NAME ENABL RUN_COUNT
    TEST_abc FALSE 0
    Note :
    As you can see from the results, the job was indeed created, but is not enabled because the ENABLE attribute was not explicitly set in the CREATE_JOB procedure.
    Run your job
    SQL> begin
    2 dbms_scheduler.run_job('TEST_abc',TRUE);
    3* end;
    SQL> /
    PL/SQL procedure successfully completed.
    SQL> select job_name,enabled,run_count from user_scheduler_jobs;
    JOB_NAME ENABL RUN_COUNT
    TEST_ABC FALSE 0
    Copying Jobs
    SQL> begin
    2 dbms_scheduler.copy_job('TEST_ABC','NEW_TEST_ABC');
    3 END;
    4 /
    PL/SQL procedure successfully completed. Hope it will help you upto some level..!!
    Regards
    K

  • How to run Servlets

    Hi
    Please tell me how to run servlets in NWDS.
    I made a simple program but now I am not able to deploy/run.
    Help me out

    Hi,
    1)You have to create a J2EE Web Application project.
    2)Then create a servlet in this project.
    3)Once you are done coding the servlet, create a J2EE EAR project.
    4)Add the Web project to EAR project.
    5)Open application.xml in EAR project, goto modules section, select web component, specify the context root (like /mycontext)
    6)Build and deploy EAR.
    You can run your servlet as:
    http://<server>:<port>/mycontext/<servlet-name>
    Hope it helps.
    Rajit

  • How to call Servlet from jsp page and how to run this app using tomcat..?

    Hi ,
    I wanted to call servlet from jsp action i.e. on submit button of JSP call LoginServlet.Java file.
    Please tell me how to do this into jsp page..?
    Also i wanted to execute this application using tomcat.
    Please tell me how to do this...? what setting are required for this...? what will be url ..??
    Thanks.

    well....my problem is as follows:
    whenever i type...... http://localhost:8080/appName/
    i am getting 404 error.....it is not calling to login.jsp (default jsp)
    but when i type......http://localhost:8080/appName/login.do........it executes servlet properly.
    Basically this 'login.do' is form action (form action='/login.do').....and i wanted to execute this from login jsp only.(from submit button)
    In short can anyone please tell me how to diaplay jsp page using tomcat 5.5
    plz help me.

  • How to run Servlet in weblogic server ?

    Hi ,
    I am new to J2ee Tech.
    how to run a simple servlet program in weblogic server?
    mainly i want know how to give the address in ID.
    Now i am using htt:\\localhost :7001\Sample\HelloServlet
    but it is not working
    Please give me the steps
    Thanks
    Merlin Rosina

    Hi ,
    I am new to J2ee Tech.
    how to run a simple servlet program in weblogic server?
    mainly i want know how to give the address in ID.
    Now i am using htt:
    localhost :7001\Sample\HelloServlet
    but it is not working
    Please give me the steps

Maybe you are looking for

  • How do I open my .cwk files

    I recently decided to turn on File Vault for security reasons. My Appleworks installation has never worked properly, but I have always been able to use old templates to type up my invoices, letters, etc. Since turning on the File Vault, I cannot acce

  • Why does (only)Nightly erase(delete) clipboard contents when I close it on my Win 8.1 64 bit HP desktop?

    After using Nightly for several months on a new HP Win 8.1 64-bit All-in-One desktop, I've noticed that if I have copied anything from Nightly to the clipboard, it disappears when Nightly is closed, and is not available to be pasted into any applicat

  • Substitution Variable problem in member formula

    I'm using the following member formula for a member in a sparse dimension - Scenario. @VAR("Actual",&PO_PriorLE->"Final"); I can get this to validate in Essbase, but when I try putting it into Planning, the refresh to Essbase bombs and the formula wi

  • LOCKS IN TABLE

    Hi If there is a table level lock what should we do to realease the lock on the table. Thanks

  • Catalyst/Chromium causes screen to flash wildly then crashes computer.

    I'm using catalyst-test-pxp 14.3-1 and chromium 35.0.1916.153-1. I am using 2 monitors. The main one being my laptop's screen (LVDS) to the right and my secondary screen (CRT1) to my left. Previously I had used a single screen configuration, however