Invoking servlet's doGet() method on startup

Hi Friends,
Is there any way of invoking the servlets doGet method on server start -up.
I am using Tomcat 4.1.18.
I know that we can Invoke the servlet at stat-up i.e. it will invoke init() method osf servlet.But what if I want to invoke the doGet method on start - up?
Regards
Abhay

The doGet will require an Request and Response object. It would be easier to remove what ever logic in the doGet you need to execute to seperate methods that can be called from both the init and doGet methods.

Similar Messages

  • Binary data in a servlet's doGet method?

    Hi,
    How to write binary data in a servlet's doGet method? Anyone, please help.

    Use POST instead of GET to transfer binary data. For GET, you can only append the data in the QUERY_STRING and its length is very limited. so better use POST.

  • Problem calling servlet from doget method of another servlet

    hi,
    Iam trying to post an html form written in the doGet() method
    of a servlet to pass this information to another servlet's doPost() method. Iam giving the following URL:
    "<FORM ACTION=http://localhost:8080/examples/servlet/UpdateProcessServlet" +
    "METHOD=POST>"
    But its not happening,the error says that "the page cannot be found" The servlet is not getting called at all. would someboy please help me in this regard.
    Thanks

    #1 Iam calling servlet 2 from here
    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException
    session=request.getSession(false);
    out.println
    (ServletUtilities.DOCTYPE +
    "<!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.0 Transitional//EN>"+
    "<HTML>" +
    "<BODY>" +
    "<P CLASS=LARGER>" +
    "<FORM ACTION=http://localhost:8080/examples/servlet/UpdateProcessServlet METHOD=POST>"
    "<INPUT TYPE=SUBMIT NAME=submitButton Value=submit>" +
    "</BODY> " +
    "</HTML>" );
    #2 This should get called and print me "Iam in doPost method
    public void doPost(HttpServletRequest request,HttpServletResponse response)
    throws ServletException,IOException
    url = "jdbc:odbc:Resume";
    System.out.println("Iam in doPost method");
    response.setContentType("text/html");
    out = response.getWriter();
    out.println("This is the last servlet for this project:");
    bool=false;
    check=false;
    Thank...:)

  • DoGet() method is being called every 3inutes repetitively in servlet

    HI,
    There are 2 managed servers in one unix box.
    i have one war application deployed in cluster level. This war application will search the logs and will give particular content as a result.
    The Jsp page will send the request and it is able to get the correct results if the operation completes within 3 minutes. if there are so many logs, it is giving unreliable results as war application is sending the request again and again in the interval of 3 mins.
    Request parameters are getting by servlet, and this servlet will create the unix shellscript in background and it will execute in a box.
    0-3 mins 1st .sh creating and executing..
    3-6 mins 2nd .sh creats and starts the execution, once the 1 one is completed...
    its becomes infinite loop...
    after some time Browser is going to diagnostic error state..
    i did debugging there i can see doGet method of servlet is being called for every 3 minutes..
    to avoid this i tried to give some parameters in weblogic.xml file...but its not working..
    please fine below weblogic.xml file
    ====================================
    <?xml version='1.0' encoding='UTF-8'?>
    <weblogic-web-app xmlns="http://xmlns.oracle.com/weblogic/weblogic-web-app" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.2/weblogic-web-app.xsd">
    <session-descriptor>
    </session-descriptor>
    <jsp-descriptor>
    <page-check-seconds>-1</page-check-seconds>
    <debug>true</debug>
    </jsp-descriptor>
    <container-descriptor>
    <resource-reload-check-secs>-1</resource-reload-check-secs>
    <servlet-reload-check-secs>-1</servlet-reload-check-secs>
    <prefer-web-inf-classes>true</prefer-web-inf-classes>
    </container-descriptor>
    <logging>
    <log-filename>/wls_domains/b2borap2/application_MT/logs/messagetracker.log</log-filename>
    </logging>
    </weblogic-web-app>
    =======================================================
    and web.xml file is
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:javaee="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <listener>
    <listener-class>
    com.tm.messagetracker.listeners.MTrackerSession
    </listener-class>
    </listener>
    <servlet>
    <servlet-name>Controller</servlet-name>
    <servlet-class>com.tm.messagetracker.Controller</servlet-class>
    <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
    <servlet-name>Controller</servlet-name>
    <url-pattern>*.do</url-pattern>
    </servlet-mapping>
    <session-config>
    <session-timeout>30</session-timeout>
    </session-config>
    <mime-mapping>
    <extension>txt</extension>
    <mime-type>text/plain</mime-type>
    </mime-mapping>
    <mime-mapping>
    <extension>html</extension>
    <mime-type>text/html</mime-type>
    </mime-mapping>
    <mime-mapping>
    <extension>htm</extension>
    <mime-type>text/html</mime-type>
    </mime-mapping>
    <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>index.html</welcome-file>
    </welcome-file-list>
    </web-app>
    =========================================
    please find the servlet code..
    public class Controller extends HttpServlet
    public void init()
    public void doGet(HttpServletRequest req, HttpServletResponse res)
    throws ServletException, IOException
         System.out.println("Iam at doGet");
    res.setContentType("text/html");
    HttpSession session = req.getSession (false);
    if (session==null) {
         // We Send a Redirect
         res.sendRedirect("./../pages/login.jsp");
    //HttpSession session = req.getSession(true);
    boolean loginTravelled = new Boolean((String)session.getAttribute("loginTravelled")).booleanValue();
    UserVerification uv = new UserVerification();
    MTUtils mTUtils = new MTUtils();
    Properties systemProps = SerializeProperties.doLoad();
    int noOFrecordsPerPage = 10;
    if (loginTravelled)
         System.out.println("loginTravelled value :"+loginTravelled);
    String pageId = req.getParameter("pageId");
    String actionId = req.getParameter("actionId");
    if (actionId.equals("logout"))
    session.removeAttribute("CompleteSearchRecords");
    session.removeAttribute("DisplaySearchRecords");
    session.invalidate();
    System.gc();
    res.sendRedirect("./../pages/login.jsp");
    else if (pageId.equals("faq"))
    if (actionId.equals("homepage"))
    System.gc();
    res.sendRedirect("./../pages/login.jsp");
    else if (actionId.equals("download"))
    String fileName = req.getParameter("fileName");
    String originalFileName = req.getParameter("originalFileName");
    doDownload(req, res, fileName, originalFileName);
    else if (pageId.equals("login"))
    if (actionId.equals("downloads"))
    List downloadListRecords = null;
    try
    downloadListRecords = DownloadableRecords.getDownloadableRecords(new File(systemProps.getProperty("faq")));
    catch (Exception e)
    e.printStackTrace();
    session.setAttribute("DownloadListRecords", downloadListRecords);
    res.sendRedirect("./../pages/downloads.jsp");
    else if (actionId.equals("userlogin"))
    String userId = req.getParameter("uname").trim();
    String password = req.getParameter("passwd").trim();
    if ((userId != null) && (userId.length() > 0) && (password != null) && (password.length() > 0))
    if ((userId.equals("superadmin")) && (password.equals("superadmin")))
    res.sendRedirect("./../pages/admin.jsp");
    String userAuthMsg = UserVerification.verifyUser(userId, password);
    if (userAuthMsg.equals("adminuser"))
    res.sendRedirect("./../pages/admin.jsp");
    else if (userAuthMsg.equals("guestuser"))
    res.sendRedirect("./../pages/search.jsp");
    else if (userAuthMsg.equals("wrongpassword"))
    res.sendRedirect("./../pages/login.jsp?userAuthDispMsg=Sorry wrong password");
    else if (userAuthMsg.equals("unauthorizeduser"))
    res.sendRedirect("./../pages/login.jsp?userAuthDispMsg=User is not Authorized ");
    else if ((userAuthMsg.equals("adminpropsNotFound")) || (userAuthMsg.equals("guestpropsNotFound")))
    res.sendRedirect("./../pages/error.jsp?userAuthDispMsg=user configurations not found , Please contact admin");
    else
    res.sendRedirect("./../pages/login.jsp?userAuthDispMsg=UserName or password cannot be null");
    else if (pageId.equals("adminPage"))
    if (actionId.equals("adduser"))
    CommonProperties adminProps = MTrackerProperties.getAdminProps();
    CommonProperties guestProps = MTrackerProperties.getGuestProps();
    String userId = req.getParameter("adduname").trim();
    String password = req.getParameter("passwd").trim();
    String userAuthMsg = uv.verifyUser(userId);
    if (userAuthMsg.equals("adminuser"))
    res.sendRedirect("./../pages/admin.jsp?userAuthDispMsg=Admin user with name exists");
    else if (userAuthMsg.equals("guestuser"))
    res.sendRedirect("./../pages/admin.jsp?userAuthDispMsg=Guest user with name exists");
    else
    String userType = req.getParameter("usertype").trim();
    if (userType.equals("admin"))
    adminProps.addProperty(userId, password);
    res.sendRedirect("./../pages/admin.jsp?userAuthDispMsg=User " + userId + " added successfully");
    else
    guestProps.addProperty(userId, password);
    res.sendRedirect("./../pages/admin.jsp?userAuthDispMsg=User " + userId + " added successfully");
    else if (actionId.equals("deleteuser"))
    CommonProperties adminProps = MTrackerProperties.getAdminProps();
    CommonProperties guestProps = MTrackerProperties.getGuestProps();
    String userId = req.getParameter("deluname").trim();
    String userAuthMsg = uv.verifyUser(userId);
    if (userAuthMsg.equals("adminuser"))
    adminProps.deleteProperty(userId);
    res.sendRedirect("./../pages/admin.jsp?userAuthDispMsg=Admin user " + userId + " deleted");
    else if (userAuthMsg.equals("guestuser"))
    guestProps.deleteProperty(userId);
    res.sendRedirect("./../pages/admin.jsp?userAuthDispMsg=Guest user " + userId + " deleted");
    else
    res.sendRedirect("./../pages/admin.jsp?userAuthDispMsg=User " + userId + " does not exists ");
    else if (actionId.equals("updatescript"))
    String perlScriptLoc = req.getParameter("perlloc").trim();
    SerializeProperties.doSave(perlScriptLoc);
    try
    Thread.sleep(2500L);
    catch (InterruptedException e) {
    e.printStackTrace();
    res.sendRedirect("./../pages/admin.jsp?userAuthDispMsg=Perl script location updated with -> " + perlScriptLoc);
    else if (actionId.equals("updatepropertyfile"))
    String propfileLoc = req.getParameter("proploc").trim();
    SerializeProperties.doSave(propfileLoc);
    try
    Thread.sleep(2500L);
    catch (InterruptedException e) {
    e.printStackTrace();
    res.sendRedirect("./../pages/admin.jsp?userAuthDispMsg=Property file location updated with -> " + propfileLoc);
    else if (actionId.equals("searchLink"))
    res.sendRedirect("./../pages/search.jsp");
    if (actionId.equals("cleanup"))
    String resultsDir = systemProps.getProperty("results");
    mTUtils.deleteFiles(new File(resultsDir), 24);
    res.sendRedirect("./../pages/admin.jsp?userAuthDispMsg=Cleanup Done !!!");
    else if (pageId.equals("searchPage"))
         System.out.println("Start searching process Here");
         if (actionId.equals("search"))
         System.out.println("Started searching process");
    String tboxValue = req.getParameter("tbox");
    String tareaValue = req.getParameter("tarea");
    String SearchString = "";
    String auditEnable = req.getParameter("audit");
    String errorEnable = req.getParameter("error");
    String debugEnable = req.getParameter("debug");
    String srchStartDate = req.getParameter("srchstartDate");
    String srchEndDate = req.getParameter("srchendDate");
    String srchInZipFile = "";
    if (req.getParameter("srchInZipFile") != null) {
    srchInZipFile = req.getParameter("srchInZipFile");
    String mode = req.getParameter("inputmode");
    try
    if (req.getParameter("recordsPerPage") != null)
    noOFrecordsPerPage = new Integer(req.getParameter("recordsPerPage")).intValue();
    catch (Exception e)
    res.sendRedirect("./../pages/error.jsp?userAuthDispMsg=recordsPerPage should be a number");
    if (mode.equals("single"))
    SearchString = tboxValue;
    else
    SearchString = tareaValue;
    String inputDir = systemProps.getProperty("inputs");
    String resultsDir = systemProps.getProperty("results");
    String inputFileName = new Integer(mTUtils.getRandom()).toString();
    File inputParams = new File(inputDir + "/" + inputFileName + ".properties");
    File inputTxt = new File(inputDir + "/" + inputFileName + ".txt");
    synchronized (inputParams) {
         System.out.println("inputParams"+inputParams);
    synchronized (inputTxt)
         System.out.println("inputtxt"+inputTxt);
    boolean saved = false;
    CommonProperties singleSerProps = new CommonProperties(inputParams);
    Properties searchProps = new Properties();
    searchProps.setProperty("search_from_date", srchStartDate);
    searchProps.setProperty("search_to_date", srchEndDate);
    searchProps.setProperty("force_zip_search", srchInZipFile);
    if ((SearchProperties.saveSingeSearchProps(singleSerProps, searchProps)) && (SearchProperties.saveSearchFile(inputTxt, SearchString)))
    if (mTUtils.genarateScript(auditEnable, debugEnable, errorEnable, srchInZipFile, inputFileName))
    if (mTUtils.runScript("sh", inputFileName))
    List tRecords = null;
    TrackingLogReader treader = new TrackingLogReader();
    try
    tRecords = treader.getRecords(new File(resultsDir), inputFileName);
    catch (Exception e)
    e.printStackTrace();
    if (tRecords == null)
    tRecords = new ArrayList();
    tRecords.add("No Records Found");
    String backEnb = "";
    String nextEnb = "";
    int fromRec = 0;
    int toRec = 0;
    if (tRecords.size() > noOFrecordsPerPage)
    toRec = noOFrecordsPerPage;
    backEnb = "false";
    nextEnb = "true";
    else
    toRec = tRecords.size();
    backEnb = "false";
    nextEnb = "false";
    List subList = tRecords.subList(fromRec, toRec);
    session.setAttribute("CompleteSearchRecords", tRecords);
    session.setAttribute("DisplaySearchRecords", subList);
    session.setAttribute("fromRec", new Integer(fromRec));
    session.setAttribute("toRec", new Integer(toRec));
    session.setAttribute("nextEnb", nextEnb);
    session.setAttribute("backEnb", backEnb);
    session.setAttribute("recsPerPage", new Integer(noOFrecordsPerPage));
    res.sendRedirect("./../pages/SearchResults.jsp");
    else {
    res.sendRedirect("./../pages/error.jsp?userAuthDispMsg=Problem in calling PERL system , Please contact admin");
    else
    res.sendRedirect("./../pages/error.jsp?userAuthDispMsg=Script not generated , Please contact admin");
    else
    res.sendRedirect("./../pages/error.jsp?userAuthDispMsg=Search input directory not found, Please contact admin ");
    //inputParams.delete();
    //inputTxt.delete();
    else if (pageId.equals("searchresults"))
    noOFrecordsPerPage = ((Integer)session.getAttribute("recsPerPage")).intValue();
    if (actionId.equals("newSearch"))
    session.removeAttribute("CompleteSearchRecords");
    session.removeAttribute("DisplaySearchRecords");
    session.removeAttribute("fromRec");
    session.removeAttribute("toRec");
    session.removeAttribute("recsPerPage");
    System.gc();
    res.sendRedirect("./../pages/search.jsp");
    else if (actionId.equals("first"))
    List completeRecords = (List)session.getAttribute("CompleteSearchRecords");
    int fromRec = 0;
    int toRec = 0;
    String backEnb = "";
    String nextEnb = "";
    if (completeRecords.size() > noOFrecordsPerPage)
    toRec = noOFrecordsPerPage;
    backEnb = "false";
    nextEnb = "true";
    else
    toRec = completeRecords.size();
    backEnb = "false";
    nextEnb = "false";
    List subList = completeRecords.subList(fromRec, toRec);
    session.setAttribute("CompleteSearchRecords", completeRecords);
    session.setAttribute("DisplaySearchRecords", subList);
    session.setAttribute("fromRec", new Integer(fromRec));
    session.setAttribute("toRec", new Integer(toRec));
    session.setAttribute("nextEnb", nextEnb);
    session.setAttribute("backEnb", backEnb);
    session.setAttribute("recsPerPage", new Integer(noOFrecordsPerPage));
    res.sendRedirect("./../pages/SearchResults.jsp");
    else if (actionId.equals("last"))
    List completeRecords = (List)session.getAttribute("CompleteSearchRecords");
    int fromRec = 0;
    int toRec = completeRecords.size();
    String backEnb = "";
    String nextEnb = "";
    if (noOFrecordsPerPage > completeRecords.size())
    fromRec = 0;
    backEnb = "false";
    nextEnb = "false";
    else
    fromRec = completeRecords.size() - noOFrecordsPerPage;
    backEnb = "true";
    nextEnb = "false";
    List subList = completeRecords.subList(fromRec, toRec);
    session.setAttribute("CompleteSearchRecords", completeRecords);
    session.setAttribute("DisplaySearchRecords", subList);
    session.setAttribute("fromRec", new Integer(fromRec));
    session.setAttribute("toRec", new Integer(toRec));
    session.setAttribute("nextEnb", nextEnb);
    session.setAttribute("backEnb", backEnb);
    session.setAttribute("recsPerPage", new Integer(noOFrecordsPerPage));
    res.sendRedirect("./../pages/SearchResults.jsp");
    else if (actionId.equals("back"))
    List completeRecords = (List)session.getAttribute("CompleteSearchRecords");
    int fromRec = ((Integer)session.getAttribute("fromRec")).intValue();
    int toRec = ((Integer)session.getAttribute("toRec")).intValue();
    toRec = fromRec;
    if (fromRec - noOFrecordsPerPage > 0)
    session.setAttribute("backEnb", "true");
    fromRec -= noOFrecordsPerPage;
    else
    fromRec = 0;
    session.setAttribute("backEnb", "false");
    session.setAttribute("nextEnb", "true");
    session.setAttribute("fromRec", new Integer(fromRec));
    session.setAttribute("toRec", new Integer(toRec));
    List subList = completeRecords.subList(fromRec, toRec);
    session.setAttribute("DisplaySearchRecords", subList);
    res.sendRedirect("./../pages/SearchResults.jsp");
    else if (actionId.equals("next"))
    List completeRecords = (List)session.getAttribute("CompleteSearchRecords");
    int fromRec = ((Integer)session.getAttribute("fromRec")).intValue();
    int toRec = ((Integer)session.getAttribute("toRec")).intValue();
    fromRec = toRec;
    if (toRec + noOFrecordsPerPage <= completeRecords.size())
    session.setAttribute("nextEnb", "true");
    toRec += noOFrecordsPerPage;
    else
    toRec = completeRecords.size();
    session.setAttribute("nextEnb", "false");
    session.setAttribute("backEnb", "true");
    session.setAttribute("fromRec", new Integer(fromRec));
    session.setAttribute("toRec", new Integer(toRec));
    List subList = completeRecords.subList(fromRec, toRec);
    session.setAttribute("DisplaySearchRecords", subList);
    res.sendRedirect("./../pages/SearchResults.jsp");
    else if (actionId.equals("download"))
    String fileName = req.getParameter("fileName");
    String originalFileName = req.getParameter("originalFileName");
    doDownload(req, res, fileName, originalFileName);
    else
    res.sendRedirect("./../pages/login.jsp?userAuthDispMsg=Invalid USER");
    public void doPost(HttpServletRequest req, HttpServletResponse res)
    throws ServletException, IOException
    doGet(req, res);
    private void doDownload(HttpServletRequest req, HttpServletResponse resp, String filename, String original_filename)
    throws IOException
    File f = new File(filename);
    int length = 0;
    ServletOutputStream op = resp.getOutputStream();
    ServletContext context = getServletConfig().getServletContext();
    String mimetype = context.getMimeType(filename);
    resp.setContentType(mimetype != null ? mimetype : "application/octet-stream");
    resp.setContentLength((int)f.length());
    resp.setHeader("Content-Disposition", "attachment; filename=\"" + original_filename + "\"");
    byte[] bbuf = new byte[10240];
    DataInputStream in = new DataInputStream(new FileInputStream(f));
    while ((in != null) && ((length = in.read(bbuf)) != -1))
    op.write(bbuf, 0, length);
    in.close();
    op.flush();
    op.close();
    =========================
    anyone please help me on above......Thanks in advance..

    Hi jleech,
    Thanks for the reply. But deleting all the temporary internet files as also the history files does not seem to have an effect. the doFilter is being called only at the second request. or did i miss anything??
    Please help. unable to complete the assignment because of this.
    Thank You,
    Phani Kanuri

  • Write a servlet without doGet() and doPost() methods

    Hi,
    Can we write a servlet without doGet() and doPost() methods ?

    public class MyCoolServlet extends HttpServlet
    public void init(ServletConfig servletConfig) throws ServletException
    public void service(HttpServletRequest request, HttpServletResponse response)
         throws ServletException, IOException
    // your code here
    }Just an example on how to do it.
    A servlet is loaded by server (before any request). It will run the init function. Then pick up an request, spawn a thread and put this servlet code into the thread, give it session, request and response objects, then call serivce.
    Remember that init is called before, outside the thread, while service is inside the thread and the last to be called. Nice place to put your code.
    If you need to have some sort of init function to be called first on every request PR USER, then make your own function, and call it first in service method.
    Stuff that are put in init() function might only get runned once in the entire server lifetime. Until restart.

  • Who calls doget() method of servlet

    hello all,
    i have typical customized webserver.
    the problem i have with that is when i configure it with IP address and when i send a request through browser using HOST NAME ,its not recognizing.
    the same happens vice versa
    that is : set up host name in the http server, and when try a request through IP Address using a web browser.
    can any body clear me who calls the doGet() method of servlet. if it is USER AGENT of web browser, is there any operation executes between
    USER AGENT - DoGet() method of servlet?
    regards
    R
    Message was edited by:
    LoveOpensource

    The servlet is on the server, the browser is on the client, so, do it think it possible (unless the browser is written in Java and does it's browsing with RMI, which is patently absurd) that the browser call doGet()?
    It is rather obvious, that the browser sends an HTTP request to the Application Container (or a web server such as apache which then uses some module to communicate with the Application Container, but the end effect is the same), and that Application Container calls the doGet() method.
    Edit: And man am I slow and "wordy".

  • Why doGet() method wil be called default in servlet

    hi
    my first question is
    1.why doGet() method wil be called up first instead of doPost() method in servlet. .
    2. How to identify the browser disables the cookies.
    please help me to this questions.
    Thank u in advance.

    hi
    my first question is
    why doGet() method wil be called up first instead of
    doPost() method in servlet.This is not correct. doGet or doPost getting called depending on the request method of the HTTP request. If the request method is GET then doGet will get called, if the request method is POST then doPost will get called.
    By the way there are other request methods. If a request arrives with one of those request methods the corresponding doXXX method wil get called.
    2. How to identify the browser disables the
    cookies. There is no direct method. What you can do is set a cookie and then see if it is sent back with the next request from the same browser session.

  • Unable to invoke Servlet Directly in address bar in Weblogic10.3

    Hi,
    I am trying to invoke the servlet directly in the address bar as below
    http://localhost:7004/servlet/loginToApp
    but It's giving me following error :
    Error 404--Not Found
    From RFC 2068 Hypertext Transfer Protocol -- HTTP/1.1:
    10.4.5 404 Not Found
    The server has not found anything matching the Request-URI...................
    but the same servlet is getting invoked when I use it in jsp form submit
    <html>
         <body>
              <form method="post" action = "http://localhost:7004/servlet/loginToApp">
                   <input type="submit"/>
              </form>
         </body>
    </html>
    in web.xml I have
    <servlet>
              <servlet-name>loginToApp</servlet-name>
              <display-name>loginToApp</display-name>
              <description></description>
              <servlet-class>abc.Common.ClientBeans.LoginToApp</servlet-class>
    </servlet>
    <servlet-mapping>
              <servlet-name>loginToApp</servlet-name>
              <url-pattern>/servlet/loginToApp</url-pattern>
         </servlet-mapping>
    This works fine on Weblogic 8.3.
    Please Help here.

    Hard to tell exactly.
    I note that your JSP page does a "POST" submit, whereas when you enter the direct URL of the servlet on the address bar, it'll result in a "GET" request.
    <form method="post" action = "http://localhost:7004/servlet/loginToApp">
    I don't know what error WLS will return if the servlet can't handle a GET, but it may be something to look at.
    Do you have a doGet() method in your servlet code?
    -steve-

  • Servlet does not load on startup

    Hi Guys,
              I'm tryin to load a servlet on startup ..
              Tryin to follow what the doc say but i get this error
              in the server logs which means that the servlet is not found
              Any help wud be greatly appritiated ...
              thanx
              what the logs say >>>
              Fri Apr 28 11:52:51 PDT 2000:<I> <WebLogicServer> Invoking T3StartupDef
              StartConfigServlet weblogic.servlet.utils.ServletStartup with
              {servlet=ConfigServlet}
              Fri Apr 28 11:52:51 PDT 2000:<I> <WebLogicServer> T3StartupDef
              StartConfigServlet weblogic.servlet.utils.ServletStartup
              reports:servlet: ConfigServlet not found
              Fri Apr 28 11:52:51 PDT 2000:<I> <SSLListenThread> Listening on port:
              7002
              Fri Apr 28 11:52:51 PDT 2000:<I> <ListenThread> Listening on port: 7001
              my server configuration>>>>
              weblogic.httpd.register.ConfigServlet=com.fourcharity.servlet.ConfigServlet
              # Set initArgs
              weblogic.httpd.initArgs.ConfigServlet=\
              servletHost=10.10.10.126:7001,\
              smtpHost=4charity.com,\
              [email protected],\
              fclogourl=http://www.4charity.com/img/donate/4c_logo.gif
              # Configure the ServletStartup class to run ConfigServlet's init()
              # method at startup
              weblogic.system.startupClass.StartConfigServlet=weblogic.servlet.utils.ServletStartup
              weblogic.system.startupArgs.StartConfigServlet=servlet=com.fourcharity.servlet.ConfigServlet
              regards sanjay
              www.eBusinessDesign.com
              3475 Granada Ave, Apt# 319,Santa Clara, CA-95051
              (1-415-2671363(o) 1-408-2492716(r) 1-877-8993286(fax))
              

              Thanks for the reply. However, the final product is to run in Solaris,
              so there should not be a problem. Thanks anyway.
              Regards,
              Baivab
              Mettu Kumar <[email protected]> wrote:
              >what problems are you facing with sp8.
              >
              >Baivab Mitra wrote:
              >
              >> Hi All!!
              >>
              >> Thanks beforehand for all help received to this query
              >beforehand.
              >>
              >> We are using WL5.1 on WinNT, with SP6. Unfortunately,
              >we have followed
              >> all instructions as in the docs. and tried to load the
              >servlet
              >> on WL startup automatically. It does not work!! Checking
              >the Internet,
              >> we came to know the SP8 is required. Installed SP8 and
              >again tried.
              >> Now -- the EJBs are giving problems -- deployment.
              >>
              >> Please -- is there anyone who can suggest remidies to
              >this? BETTER
              >> if we could stick to SP6 and NOT switch to SP8.
              >>
              >> Thanks,
              >>
              >> Baivab
              >
              

  • Re: How do I invoke Servlets...continued

    Hi Howard,
              Could you show us web.xml?
              Regards,
              Slava Imeshev
              "Howard Hyde" <[email protected]> wrote in message
              news:3ccedf8a$[email protected]..
              > My posting appears to have been truncated, so here is the remainder:
              > (continued)
              > 'Pilot' is a servlet defined and mapped in my web.xml file. But when I
              attempt
              > to invoke the servlet in the app with any of the following:
              > http://localhost:7001/pilots/Pilot
              > http://localhost:7001/pilots/pilot
              > http://localhost:7001/pilots/servlet/Pilot
              > http://localhost:7001/pilots/servlet/pilot
              >
              > ... I get a 404 error.
              >
              > However, the following JSP, which is part of the same web application
              component
              > of the Enterprise app, works:
              > http://localhost:7001/pilots/Rating.jsp
              >
              > So the question of the day once again, is:
              >
              > How do I invoke servlets in an enterprise application?
              >
              > Best regards,
              >
              > Howard
              > 818-366-2686
              

    and to add to matt's post:
              in the servlet init() method trace out some debug to ensure that new
              versions of your servlet are actually being deployed:
              ..init() {
              System.out.println( getServletName() + " was deployed at " + " new
              Date(System.currentTimeMillis()) );
              "Matt Krevs" <[email protected]> wrote in message
              news:[email protected]...
              > 1. What stack trace do you receive, if any, when your call to your servlet
              > doesnt work
              >
              > 2. Is your servlet in a package? If it is then you need to specify the
              > package in the servlet-class element
              >
              > 3. Is it possible that your servlet-name and/or servlet-class elements in
              > web.xml have some spaces in them? Maybe you should remove the line feeds
              > etc. and specify your servlet elements as you have your servlet-mapping
              > elements
              >
              > eg like this
              >
              > <servlet>
              > <servlet-name>Pilot</servlet-name>
              > <servlet-class>FrmPilot2</servlet-class>
              > <load-on-startup>0</load-on-startup>
              > </servlet>
              >
              > 4. Do you get any deployment errors when weblogic starts up?
              >
              > 5. Try setting the load-on-startup parameter to a positive number. You may
              > receive a helpful? stacktrace when weblogic starts up
              >
              >
              > "Howard Hyde" <[email protected]> wrote in message
              > news:[email protected]...
              > > The following are EXCERPTS from the web.xml file:
              > >
              > > <web-app>
              > > <servlet>
              > > <servlet-name>
              > > Pilot
              > > </servlet-name>
              > > <servlet-class>
              > > FrmPilot2
              > > </servlet-class>
              > > <load-on-startup>
              > > 0
              > > </load-on-startup>
              > > </servlet>
              > > <servlet-mapping>
              > > <servlet-name>Pilot</servlet-name>
              > > <url-pattern>/Pilot</url-pattern>
              > > </servlet-mapping>
              > >
              > > </web-app>
              > >
              > >
              >
              >
              

  • Urgent....How can i redirect to my jsp page from servlet in init() method..

    How can i redirect to my jsp page from servlet in init() method..Becoz that servlet is calling while server startsup..so im writing some piece of code in init() method..after that i want to redirect to some jsp page ...is it possible?
    using RequestDispatcher..its not possible..becoz
    RequestDispatcher rd = sc.getRequestDispatcher("goto.jsp");
    rd.foward(req,res);
    Here the request and response are null objects..
    So mi question can frame as how can i get request/response in servlet's init method()..

    Hi guys
    did any one get a solution for this issue. calling a jsp in the startup of the servlet, i mean in the startup servlet. I do have a same req like i need to call a JSP which does some data reterival and calculations and i am putting the results in the cache. so in the jsp there in no output of HTML. when i use the URLConnection i am getting a error as below.
    java.net.SocketException: Unexpected end of file from server
    at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:707)
    at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:612)
    at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:705)
    at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:612)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLCon
    nection.java:519)
    at com.toysrus.fns.alphablox.Startup.callJSP(Unknown Source)
    at com.toysrus.fns.alphablox.Startup.init(Unknown Source)
    at org.apache.tomcat.core.ServletWrapper.doInit(ServletWrapper.java:317)
    so plz do let me know how to call a jsp in the start up of a servlet.
    Thanks
    Vidya

  • LDAP Context Initialization Problem in a Servlet's Init method

    Hi
    I have a servlet where I am using the InitialDirContext to Initialize context to a LDAP Server. I have created the context as a static variable. I am initializing the context in the init method and am using the same reference in the service method of the servlet. But if the context fails (due to naming exception and time out) in the init method all my requests in the service method will fail. Is there any way to validate the reference before using the same in the service method.
    Also what is the best approach to initialize the context in a servlet. Whether to initialize in the service method or the init method.
    I would appreciate if anyone can answer the above 2 queries.
    Thanks in advace,
    Ashish

    If you want to use threadsafe objects in doPost/doGet there are two common ways to do this.
    First, create the object in doPost/doGet. This may get expensive depending on the object, but it is 'easy' code and works.
    The second option is to create a pool of objects in the servlet's init() method and to just have doPost/doGet get an object from the pool, use it and return it when done. This take a little more work to code, but the overhead of creating objects is almost eliminated. Look at jakarta/apache commons pool for a quick way to do this.
    If you create on object in init() and use it in doPost/doGet, any time you get two request for the same servlet at the same time you will have synchronization issues that will usually cause problems. There is one instance of each Servlet, so all request for that servlet go through the single instance. Anything in doPost/doGet must be threadsafe.

  • DoGet method is called 2 times when a switch-case statement is used

    Hello all,
    I have a servlet that, when run from browser, runs the doGet method 2 times.
    I have a switch case statement within the servlet and when I comment out this servlet, it runs 1 time as expected.
    Here is the code:
    public class RSSServlet extends HttpServlet {
        /** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
         * @param request servlet request
         * @param response servlet response
        protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
            System.out.println("CALLED SERVLET");
            response.setContentType("text/xml;charset=UTF-8");
            PrintWriter out      = response.getWriter();
            DBQueriesRSS queries = new DBQueriesRSS();
            String queryType     = request.getParameter("queryType");
            String strCount      = request.getParameter("count");
            int count            = (strCount != null && !strCount.equalsIgnoreCase("null") && strCount.length() > 0) ?
                Integer.parseInt(strCount) : 25;
             if(queryType != null && !queryType.equalsIgnoreCase("null") && queryType.length() > 0) {
                System.out.println("IN IF STATEMENT");
                switch(Integer.parseInt(queryType)) {
                    case 1 : out.println(queries.getDefault(count));System.out.println("1");       break;
                    case 11: out.println(queries.getDefault(count));System.out.println("11");       break;
                    case 21: out.println(queries.getTopDaily(count));System.out.println("21");      break;
                    case 22: out.println(queries.getTopWeekly(count));System.out.println("22");     break;
                    case 23: out.println(queries.getTopMonthly(count));System.out.println("23");    break;
                    case 24: out.println(queries.getTopYearly(count));System.out.println("24");     break;
                    case 31: out.println(queries.getTopNDailyBW(count));System.out.println("31");   break;
                    case 32: out.println(queries.getTopNWeeklyBW(count));System.out.println("32");  break;
                    case 33: out.println(queries.getTopNMonthlyBW(count));System.out.println("33"); break;
                    case 34: out.println(queries.getTopNYearlyBW(count));System.out.println("34");  break;
                    default: out.println(queries.getTopWeekly(25));System.out.println("default");    break;
                System.out.println("OUT OF SWITCH");
            System.out.println("OUT OF IF");
            out.close();
        // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
        /** Handles the HTTP <code>GET</code> method.
         * @param request servlet request
         * @param response servlet response
        protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
            processRequest(request, response);
        /** Handles the HTTP <code>POST</code> method.
         * @param request servlet request
         * @param response servlet response
        protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
           processRequest(request, response);
        /** Returns a short description of the servlet.
        public String getServletInfo() {
            return "Short description";
        // </editor-fold>
    } The results from running this servlet are:
    http://localhost/proxy/RSSServlet??queryType=34&count=66
    CALLED SERVLET
    IN IF STATEMENT
    34
    OUT OF SWITCH
    OUT OF IF
    CALLED SERVLET
    IN IF STATEMENT
    34
    OUT OF SWITCH
    OUT OF IFAnyone see anything obvious?
    TIA!

    in your case you want 'count' to be a class attribute rather than a local variable. But yes, incrementing it each time that the method is called will serve your purpose.

  • How to get only the last part of the URL in the doGet() method?

    In the doGet() method is there a way to check what URL it was called from ? For example the URL was: http://localhost:8080/myproject/jsp/randomPhrase.php (the php here is purely for misleading purposes - it's all Java really). in the doGet() method I would like to get the "randomPhrase" part of the URL only - to determine where to redirect the user. How can I do that?
    Thanks.

    Hello there,
    As it seems to me the part of the URL you're looking fo,r corresponds actually to the name of the servlet, so why don't you just call the getServletName method?

  • Invoking  Servlet to insert  data  into database

    I have written a compose page in html which on clicking SEND button has to call a servlet which inserts the values entered in htmlpage int to database .
    Can any one suggest me how it is done.
    thanks....:)

    for inserting data into the database u need to do the following
    1)write the servlet doGet method.Inside it use the object of the HttpServletRequest to retrieve the values entered in the html page.The method getParameter is used for that.If it is going to be a name written in textbox it should be like
    req.getParameter("txtname");
    req being the object of the HttpServletRequest object and txtname the name of the textbox.
    2)Load the driver
    3)Fix the connection
    4)Write a preparedstatement or statement which would insert the value which is requested above
    5)Execute the query.
    thats it
    All the best
    VaijayanthiBalaraman

Maybe you are looking for

  • Manual Email Retrieve being Ignored??

    I am in Thailand, and I just got a message from AT&T that my data bill is $500 after 30 days. I have had Data Roaming turned "OFF" for the majority of my trip. I have Email retrieval set to MANUAL at all times. I have turned on Data Roaming for a spl

  • My finder is not working

    Hello, My finder was working just fine and then without downloading anything new, it has ceased to function. When I open it, I see All My Files, but if I click anywhere else, ie) desktop, all I see is the spinning beach ball. I can't get to any of my

  • Edit Audio - Clipboard not working

    I like to copy a period of recorded silence and use this rather than entering "pure" silence when a pause is required during audio edit. Whilst I can copy to the clipboard OK at the start of the process, as soon as I run the audio in edit, the clipba

  • Custom Territory

    Hi I am getting error message in Idoc during creation of material "Customs territory not created for country AT" Message Class ME Message Number 380 Could anybody ,Please help me out...!

  • [solved] Building xfce4-panel-git

    Hello. I've satisfied all depps for xfce4-panel-git. However, I have a problem: Build Configuration: * Debug Support: yes * GNU Visibility: yes * Documentation: no make all-recursive make[1]: Entering folder `/tmp/yaourt-tmp-kant/aur-xfce4-panel-git/