How to Wait in a servlet?

I want to use this command:
wait(500);
I have a simple HTTP servlet class (public class SleeperServlet extends HttpServlet) but I get this error:
java.lang.IllegalMonitorStateException: current thread not owner
Anyone know how to do what I want to do?
thanks for helping

The reason you are getting the IllegalMonitorStateException is because you are using the wait method without being in a synchornized code block. Either you should do as is suggested and use Thread.sleep() or you should place a synchronized code block around the wait method. I would not suggest this as it may cause problems in the server with multi-threading.

Similar Messages

  • How to call two different servlet-url in the same application

    Hi,
    I want to call, consecutively these methods in my application.
    response.sendRedirect(servlet-url1)
    reponse.sendRedirect(servlet-url2)
    but the second method dont answer,
    I think, the first method redirect s with response ,
    but how to call two different servlet ?
    thanks

    if you call the first redirect, the servlet is getting aborted, so you can redirect to the first servlet, working the stuff in it, and then in the second servlet you can redirect to the third servlet

  • How can I run a servlet with Sun Java System Application Server PE 8?

    I've created a package with a TestServlet.class inside, used the deploytool to create a WAR and deployed this using the autodeploy folder.
    The filestructure has been generated and I find the TestServlet.class in
    [installdir]\domains\domain1\applications\j2ee-modules\testProject\WEB-INF\classes\[packagefolderstructure]\TestServlet.class.
    The context root is working fine, but I have no clue how I can run the servlet directly via the URL.
    I've tried many things like
    http://localhost:8080/testProject/TestServlet
    http://localhost:8080/testProject/servlet/TestServlet
    http://localhost:8080/testProject/servlet/[packagenamewithpoints]TestServlet
    http://localhost:8080/testProject/servlet/[packagenamewithslashes]TestServlet
    etc etc
    Can somebody tell me please how to write URLs to deployed servlets? Or send me an example url and xml descriptor files?
    Thanks a lot in advance!

    in web.xml use servlet mapping
    <servlet-mapping>
        <servlet-name>TestServlet</servlet-name>
        <url-pattern>/doit</url-pattern>
    </servlet-mapping>then use http://localhost:8080/testProject/doit

  • How do we run a servlet program in eclipse

    how do we run a servlet program in eclipse.

    Not at all, because servlets require a servlet container. Some Eclipse plugins (Lomboz etc.) do provide integration with those.

  • How can I test a Servlet?

    Hello!
    I want to test a small part of a servlet. That part connects to a database through a DataSource which is obtained in this manner:
    Context ctx = new InitialContext();
    ds = (DataSource) ctx.lookup(dsLookup);
    conn = ds.getConnection();Details about the servlet: runs on a WebSphere application server with db2 database. Runs on the local server in our intranet and I create a Java project in Eclipse with Create project from existing source: path to location on server.
    It's really annoying to start the browser, get to the page I'm interested, make the neccesary request and then see what happens in my code.
    What I've learned so far:
    I can't test it in a main function because I can't get the context. I tried setting the context's properties, still no go.
    I found this: http://www.ibm.com/developerworks/rational/library/08/0219_jadhav/
    but I got lost when it came to adding the resource reference to the project. How can one do that in Eclipse?
    Can anyone please, please, pretty please with sugar on top, explain to me how I can do this?
    Thank you very much for your time,
    Iulia

    Thank you for your prompt reply. I still have some questions:
    You say that configuration must go in the web.xml file. I don't have that file. In the tutorial example one application is a Java project the other is an application client and the other is an EAR of the application client. Neither of them have a web.xml file. So where do I set the resource?
    Do I have to have a WebSphere application server installed on my local machine?Where and how do I run the servlet?
    Thank you,
    Iulia

  • How to wait till the end of DOS program started using Runtime.exec(cmd)?

    In my Java program I need to call two DOS batch programs namely call.bat and start.bat. First I need to start the batch program call.bat and once that program is completed, I need to call the other batch file start.bat.
    The piece of code which I am using is:
    public static void ExecuteScripts(){
    try {
    \\Start the first batch program call.bat
    Process p = Runtime.getRuntime().exec("cmd /c start .\\scripts\\call.bat");
    p.waitFor();
    System.out.println("Exit value "+p.exitValue());
    \\Start the second batch program run.bat
    Process p1 = Runtime.getRuntime().exec("cmd /c start .\\scripts\\run.bat");
    catch (Exception e) {
    e.printStackTrace();
    For this piece of code it starts the first batch program(i.e, call.bat) in a command prompt and immediately it starts the second batch program (i.e, run.bat) in another command prompt. So it runs both the batch programs simultanesously. But what I wanted is that my program should wait till the first batch is executed and then start the second batch.
    Please tell me how to wait between these two runtime commands in JAVA
    With regards,
    C.Chenthil.
    -------------------

    Hi everybody thanks a lot.
    I got a solution from another forum. Kindly find the solution
    public static void ExecuteScripts(){
    try {
    \\Start the first batch program call.bat
    Process p = Runtime.getRuntime().exec("cmd /c start/wait .\\scripts\\call.bat");
    p.waitFor();
    System.out.println("Exit value "+p.exitValue());
    \\Start the second batch program run.bat
    Process p1 = Runtime.getRuntime().exec("cmd /c start/wait .\\scripts\\run.bat");
    catch (Exception e) {
    e.printStackTrace();
    Process p = Runtime.getRuntime().exec("cmd /c start/wait .\\scripts\\call.bat"); is the switch that served my purpose.

  • How to inject ejb in servlet

    hi all
    How to inject ejb in servlet ?
    please explain how to config my servlet and my paroject
    I have an ear file with two jar files
    Thanks in advance

    hi
    I have this error in my project
    I have an ear file ,two war file and three jar file in it
    and I did configuration
    but there was this error
    14:19:45,398 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[conference-servlet].[enterLet]] Allocate exception for servlet enterLet: javax.naming.NameNotFoundException: ITrmnlAuthenticationBL not bound
    @Remote
    public interface ITrmnlAuthenticationBL{
    @Stateless
    public class TrmnlAuthenticationBL implements ITrmnlAuthenticationBL{
    public class EnterLet extends HttpServlet {
         @EJB(mappedName = "ITrmnlAuthenticationBL")
         private ITrmnlAuthenticationBL trmnlMg;
    please explain my mistake

  • How to mention encoding in servlet.

    Hi
    How to mention encoding in servlet.
    Regards
    Arghya Banerjee

    I suppose your question may refer to the setContentType method discussed here:
    http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/ServletResponse.html
    If not, ask a more specific question.

  • How to get absolute in servlet

    how to get absolute in servlet like c:\temp\apache group\tomcat4.1\test\abc.gif, thanks

    do sthing like:
    getServletContext().getRealPath("/abc.gif") in any servlet in 'test' to get the real path of abc.gif - The parameter should be relative to the current context

  • How can I let my servlet to process Chinese Character as an input?

    How can I let my servlet to process Chinese Character as an input to my simple database which is an Excel file. I have tried before and all my input values become question marks.
    Please give me some advise, thx!

    input chinese?����������
    that may result from the tomcat or other web server

  • How to insert the new Servlet Api Class files?

    Hi,
    I need to know how do I add the Servlet Api Class to my java directory
    after i download it from the net? Thanks for your help in advance!

    niceguyme,
    If you downloaded the J2EE 1.3.1 API and installed it to (for example) c:\j2ee131, then what you need to add to your class path is:
    c:\j2ee131\lib\j2ee.jar
    I also add c:\j2ee131\lib\ejb10deployment.jar to the classpath, but it is not necessary.
    there are several ways to add these to your classpath. It depends on what Operating System you are using. On windows 98 type OS, you can edit the autoexec.bat and add these directly to your already existing classpath. Windows NT,2000, and XP: you can add them to the system environment variables classpath. Hopefully you know how to do this on your machine. What I like to do on the windows machine is create a batch file that will start it from within a command prompt. I do this because there are times when I need to compile my code using different versions of the Java api. I am enclosing an example of one for J2se1.4.1 and j2ee1.3.1.
    contents of java141.bat
    @ECHO OFF
    ECHO JDK 1.4.1 and J2EE 1.3.1 are current versions
    set HOLD_CP = %CLASSPATH%
    set HOLD_PATH = %PATH%
    set CLASSPATH=.
    set CLASSPATH=%CLASSPATH%;e:\jdk14\jre\lib\rt.jar
    set CLASSPATH=%CLASSPATH%;e:\jdk14\lib\dt.jar
    set CLASSPATH=%CLASSPATH%;e:\jdk14\lib\tools.jar
    set CLASSPATH=%CLASSPATH%;e:\jdk14\lib\htmlconverter.jar
    rem **** J2EE STUFF ****
    set CLASSPATH=%CLASSPATH%;e:\j2ee131\lib\j2ee.jar
    set CLASSPATH=%CLASSPATH%;e:\j2ee131\lib\ejb10deployment.jar
    set CLASSPATH=%CLASSPATH%;%HOLD_CP%
    set PATH=e:\jdk14\bin
    set PATH=%PATH%;"C:\Program Files\TextPad 4"
    set PATH=%PATH%;c:\windows\command
    set PATH=%PATH%;%HOLD_PATH%I hope this helps.
    TJJ

  • How to invke the XSQL Servlet directly

    What I am really trying to achieve is the ability to forward an xml document to the XSQL servlet for further processing.
    How can I invoke the servlet rather than go via an xsql page and what parameters do I need to pass in order for it to work.
    I'm wondering out loud if the new filter capabilities of servlet 2.3 will achieve the desired effect.
    Any ideas?

    You can get the RequestDispatcher and call forward() on it
    to forward to an XSQL page. From another one of your posts
    it seems you might have already figured this out. :-)

  • How to attach a new servlet on my OC4J instance ?

    Hi there
    How to attach a new servlet on my OC4J instance ?
    Regards
    Den

    You can deploy your using JDeveloper:
    http://download.oracle.com/otndocs/tech/ias/portal/files/RG/OBE/deployToAppServer/lesson_Deployment.htm
    Or you can use the Application Server Control:
    http://download.oracle.com/docs/cd/B31017_01/core.1013/b28764/deploy_em003.htm
    Maurits

  • How to use a custom servlet in iFS?

    Hi,
    I'm creating a custom servlet to download files from iFS to local drive. My question is where should I put the servlet class file, and how do I invoke this servlet from a ifs jsp file?
    I'm running iFS 1.1.9, with JWS web server.
    Thanx.
    [email protected]

    Howdy:
    In the iFS Online Resources HTML whitepaper,
    there are several examples for creating and
    deploying servlets. See the section "Creating a Simple Content Management Application." Please check out: http://technet.oracle.com/products/ifs/htdocs/resources/index.htm
    Hope this helps,
    Dennis Dawson

  • How to wait until setPage(number) is finished

    SR 3-8311228061
    When calling getStrings, found I need to iterate the pages of the doc/xls/etc
    However Autovue Support tells me that setPage() is asynchronous
    I asked how to wait until setPage() is complete, they suggested I post the question here
    Note, at the time its called the viewer (desktop version 20.2.2) is on the task tray, but not rendering the document
    Its only loaded to extract the text
    here is the blip of code
    for( curPage = 1; curPage <= pages; curPage++)
    vueBean.setPage( curPage ); //its necessary to call setPage even for page 1
    //If setpage fails stop (per Daniel/Oracle)
    int thisPage = vueBean.getPage();
    if( curPage != thisPage )
    //This message never shows up
    String msg = String.format("Pages[%d] thisPage[%d] curPage[%d] ", pages, thisPage, curPage);
    AdeptApplication.INSTANCE.publishEvent("file-event", msg,
    new SystemEvent(this.fileName, "GETTEXT_PAGEFAILED"));
    break;

    The code you have is to know whether changing pages succeeded or not, and unless you are trying to set a page number that is out of the page count it will always succeed
    So, yes, your test is the same as if (false)
    Now, page loading is done in an asynchronous manner
    1. you ensure that the page (the container for all the page artifacts) is created, synchronously
    2. the page content are streamed on another thread
    3. once the page is loaded, an event is sent VueEvent(VueEvent.FILEEVENT, VueEvent.ONPAGELOADED)
    So you should be able to query for info after you received the page loaded event
    Now, word documents are an special kind of documents, so you need to be aware of some specific issues.
    The same way ms-word does not know the total number of pages until the ENTIRE document is loaded, AutoVue will not be able to notify you either.
    And as Word, AutoVue allows you to display the pages that are already loaded, and you may query for some of its contents too.  BUT you can not query for page info when the page is been loaded (or obviously not yet loaded)
    The loading is a 2 phase one, part is done on the server (native code) and part is on the java side (display)
    So you will not be able to iterate
    for( curPage = 1; curPage <= pages; curPage++)
    simply because page count is not known.  You need to query doc info more than once.
    If page count = -1, you need to iterate for each page and then, test whether setPage() != getPage() and/or page count has been updated.

Maybe you are looking for

  • How does sy-tabix affect by binary search transforming no fields?

    1 report ztx1110.      2 data: begin of it occurs 3,      3           f1(2) type n,      4           f2    type i,      5           f3(2) type c,      6           f4    type p,      7           end of it.      8      9   it-f1 = '40'. it-f3 = 'DD'. i

  • N91 No WLAN network found

    Good day sir / madam, I'm having a problem with my N91's WLAN, here's my problem. On "Connection manager>Available WLAN" menu will appear the SSID of my Wireless-N router and then will dissappaer after a few seconds, even I'm just beside the my wirel

  • Problems importing TV Shows I got from iTunes

    I purchased the first two seasons of a TV show on iTunes about 3 months ago. There was a small house fire in my home that fatally damaged my laptop. Fortunately, we recovered the hard drive and I was able to save my files. I got a new computer but iT

  • How to output header info. by using DMEE?

    Hi, When I am using DMEE to output payment file, I need to put a header info. before the itemlized transactions. For bank like Citibank, only need each transaction lines, so no header need to put. But some bank, need a header info. in front of the it

  • How can I get Mail to stop automatically opening on startup of my MacBook?

    How can I get Mail to stop automatically opening on startup of my MacBook Pro? It's not in my startup items folder. But it auto-opens every time I boot up