How to call a servlet  by  java standalone application

//program related to calling a servlet by java standalone application and printing the response on console
import java.io.*;
import java.util.*;
import java.lang.Object;
import java.net.*;
public class Program
     public static void main(String s[])
     System.out.println("Hello this programm defines about how to call a servlet with a java application ");
     try{
          URL servlet = new URL("http://localhost:8080/anchor/studentform.html");
          URLConnection conn=servlet.openConnection();
          conn.setDoOutput(true);
          InputStreamReader isr=new InputStreamReader(conn.getInputStream());
          BufferedReader br = new BufferedReader(isr);
          String str =br.readLine();
          System.out.println("Source code is" +str);          
     catch(IOException e)
     System.out.println("exception is" +e);
i am able to read only one line of the form, please help me out to read the whole form (file)

You are only reading one line? Why aren't you reading the data in a loop? E.g. a while loop. (Keep reading till readLine returns null)
Kaj

Similar Messages

  • How to call Oracle Reports via Java Web Application ?

    Dear All,
    I have developed a web reports using Oracle Reports 11g and would like to display these reports via Java Web App that will call them.
    Kindly help me in this matter.
    Regards,
    Irfan

    i will go as John suggested.........Construct a URL with required parameters and call it using goLink component
    make a configuration in Report server and
    http://myServer:myport/reports/rwservlet?config=myconfig&destype=cache&desformat=PDF&report=myreport.jsp&myparameter=myvalue

  • Calling a servlet from java

    How to call a servlet from java?
    your help is greatly appreciated..

    Welcome to the forum
    You seem to be misunderstanding something. Do some googling to learn what you need about servlets. Simplified, servlets are java code that's hosted by a web container, such as Tomcat. When a servlet gets called as a consequence of someone requesting a url from the container, it takes in a request object and a response object. All the magic is then in creating an appropriate response (e.g. html) for the incoming request.

  • How to call a servlet in new window without toolbar from OA page

    How to call a servlet in new window without toolbar from a OA page?Please provide sample code

    I have tried with the way suggested in Mukul's blog using javascript in Destination URI property.
    I tried to open a OA Page and from which forwarded it to a servlet..
    It is showing the error:
    Error Page
    Exception Details.
    oracle.apps.fnd.framework.OAException: The application id or shortname () you entered does not exist.
         at oracle.apps.fnd.framework.webui.OAPageErrorHandler.prepareException(OAPageErrorHandler.java:1223)
         at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(OAPageBean.java:1969)
         at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(OAPageBean.java:502)
         at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(OAPageBean.java:423)
         at oa_html._OA._jspService(_OA.java:86)
         at oracle.jsp.runtime.HttpJsp.service(HttpJsp.java:119)
         at oracle.jsp.app.JspApplication.dispatchRequest(JspApplication.java:385)
         at oracle.jsp.JspServlet.doDispatch(JspServlet.java:259)
         at oracle.jsp.JspServlet.internalService(JspServlet.java:178)
         at oracle.jsp.JspServlet.service(JspServlet.java:148)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:588)
         at oracle.jsp.provider.Jsp20RequestDispatcher.forward(Jsp20RequestDispatcher.java:162)
         at oracle.jsp.runtime.OraclePageContext.forward(OraclePageContext.java:175)
         at oa_html._OA._jspService(_OA.java:96)
         at oracle.jsp.runtime.HttpJsp.service(HttpJsp.java:119)
         at oracle.jsp.app.JspApplication.dispatchRequest(JspApplication.java:385)
         at oracle.jsp.JspServlet.doDispatch(JspServlet.java:259)
         at oracle.jsp.JspServlet.internalService(JspServlet.java:178)
         at oracle.jsp.JspServlet.service(JspServlet.java:148)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:588)
         at org.apache.jserv.JServConnection.processRequest(JServConnection.java:456)
         at org.apache.jserv.JServConnection.run(JServConnection.java:294)
         at java.lang.Thread.run(Thread.java:534)
    ## Detail 0 ##
    oracle.apps.fnd.framework.OAException: The application id or shortname () you entered does not exist.
         at oracle.apps.fnd.framework.webui.OAWebBeanFactoryImpl.getAppId(OAWebBeanFactoryImpl.java:5391)
         at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(OAPageBean.java:969)
         at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(OAPageBean.java:502)
         at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(OAPageBean.java:423)
         at oa_html._OA._jspService(_OA.java:86)
         at oracle.jsp.runtime.HttpJsp.service(HttpJsp.java:119)
         at oracle.jsp.app.JspApplication.dispatchRequest(JspApplication.java:385)
         at oracle.jsp.JspServlet.doDispatch(JspServlet.java:259)
         at oracle.jsp.JspServlet.internalService(JspServlet.java:178)
         at oracle.jsp.JspServlet.service(JspServlet.java:148)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:588)
         at oracle.jsp.provider.Jsp20RequestDispatcher.forward(Jsp20RequestDispatcher.java:162)
         at oracle.jsp.runtime.OraclePageContext.forward(OraclePageContext.java:175)
         at oa_html._OA._jspService(_OA.java:96)
         at oracle.jsp.runtime.HttpJsp.service(HttpJsp.java:119)
         at oracle.jsp.app.JspApplication.dispatchRequest(JspApplication.java:385)
         at oracle.jsp.JspServlet.doDispatch(JspServlet.java:259)
         at oracle.jsp.JspServlet.internalService(JspServlet.java:178)
         at oracle.jsp.JspServlet.service(JspServlet.java:148)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:588)
         at org.apache.jserv.JServConnection.processRequest(JServConnection.java:456)
         at org.apache.jserv.JServConnection.run(JServConnection.java:294)
         at java.lang.Thread.run(Thread.java:534)
    oracle.apps.fnd.framework.OAException: The application id or shortname () you entered does not exist.
         at oracle.apps.fnd.framework.webui.OAWebBeanFactoryImpl.getAppId(OAWebBeanFactoryImpl.java:5391)
         at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(OAPageBean.java:969)
         at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(OAPageBean.java:502)
         at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(OAPageBean.java:423)
         at oa_html._OA._jspService(_OA.java:86)
         at oracle.jsp.runtime.HttpJsp.service(HttpJsp.java:119)
         at oracle.jsp.app.JspApplication.dispatchRequest(JspApplication.java:385)
         at oracle.jsp.JspServlet.doDispatch(JspServlet.java:259)
         at oracle.jsp.JspServlet.internalService(JspServlet.java:178)
         at oracle.jsp.JspServlet.service(JspServlet.java:148)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:588)
         at oracle.jsp.provider.Jsp20RequestDispatcher.forward(Jsp20RequestDispatcher.java:162)
         at oracle.jsp.runtime.OraclePageContext.forward(OraclePageContext.java:175)
         at oa_html._OA._jspService(_OA.java:96)
         at oracle.jsp.runtime.HttpJsp.service(HttpJsp.java:119)
         at oracle.jsp.app.JspApplication.dispatchRequest(JspApplication.java:385)
         at oracle.jsp.JspServlet.doDispatch(JspServlet.java:259)
         at oracle.jsp.JspServlet.internalService(JspServlet.java:178)
         at oracle.jsp.JspServlet.service(JspServlet.java:148)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:588)
         at org.apache.jserv.JServConnection.processRequest(JServConnection.java:456)
         at org.apache.jserv.JServConnection.run(JServConnection.java:294)
         at java.lang.Thread.run(Thread.java:534)

  • How to call external files from java?

    How to call external files in java. For example how to call a *.pdf file to open in its default editor(say Acrobat), or a *.html file to open in the default browser or a *.txt file in a notepad etc..,
    In my program i have *.chm (Compiled Windows HTML Help) help file. how to open it in its default editor it?

    Jayarathina_Madharasan wrote:
    no one answered my questionHi what wrong did i do...basically insulted all the volunteers here who took the time to consider your question and try to offer you help. Other than that, you did nothing wrong.
    From JavaRanch :
    And even if an answer doesn't solve your problem, even if it should totally miss the point - the best thing to do to motivate others to continue trying to help you is showing respect and gratitude for the investment of time that was put into dealing with your issue.
    Edited by: Encephalopathic on Apr 14, 2008 10:01 AM

  • Calling a servlet in java class

    Hello,
    I try to call a servlet from java class
    but is dose not work
    what should be the problem
       public void callServlet()
              try
                            // xxservlet is the servlet name
                   URL url = new URL("http://www.mydomain.com/xxservlet");
                   URLConnection hpCon = url.openConnection();
                   hpCon.setDoOutput(true);
                   OutputStreamWriter out = new OutputStreamWriter(hpCon.getOutputStream());
                   out.write("This Is a Test");
                   out.flush();
                   out.close();
              }catch(Exception ex){ex.printStackTrace();}     
    // My Servlet  is in package servlets
    public class XXServlet extends HttpServlet
        public void service(HttpServletRequest req, HttpServletResponse resp) {
            try {
                 ServletInputStream sin = req.getInputStream();
                 int len = req.getContentLength();
                    byte[] input = new byte[len];
                    ServletInputStream sin = req.getInputStream();
                   int c, count = 0 ;
                   while ((c = sin.read(input, count, input.length-count)) != -1) {
                       count +=c;
                  sin.close();
                  String inString = new String(input);
                  System.out.println("Servlet is running ...."+inString);
            } catch (IOException e) {
                try{
                    resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
                    resp.getWriter().print(e.getMessage());
                    resp.getWriter().close();
                } catch (IOException ioe) {
    // web.xml
    <servlet>
           <servlet-name>xxservlet</servlet-name>
           <servlet-class>servlets.XXServlet</servlet-class>
        </servlet>
       <servlet-mapping>
        <servlet-name>xxservlet</servlet-name>
        <url-pattern>/xxservlet</url-pattern>
      </servlet-mapping>
    }regards
    Edited by: the_Orient on Mar 30, 2009 3:16 AM

    I have start servlet from brwoser only to test that servlet works fine
    A gain what I need
    I want to call a servlet from a javs class
    URL url = new URL("http://www.mydomain.com/myservlet");
      URLConnection hpCon = url.openConnection();
      hpCon.setDoOutput(true);
      OutputStreamWriter out = new OutputStreamWriter(hpCon.getOutputStream());
      out.write("Hello Woprld");
      out.flush();
      out.close();// Servlet
    public void doGet(HttpServletRequest req, HttpServletResponse resp) {
            try {
                  String xp =req.getSession().getServletContext().getRealPath("/");
                  File f = new File(xp+"/students/info.txt");
                  f.createNewFile();
            } catch (IOException e) {
                try{
                    resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
                    resp.getWriter().print(e.getMessage());
                    resp.getWriter().close();
                } catch (IOException ioe) {
    problem file can not be created
        public void doPost(HttpServletRequest req, HttpServletResponse resp)
    }I hope that is clear

  • How To Call HTML Page Through Java Swing Page  ???....

    Hi All ;
    Please Can You Tell Me How To Call HTML Page Through Java Swing Page ....
    Regards ;

    Hi,
    you can use HTML fragments on a panel.
    http://java.sun.com/docs/books/tutorial/uiswing/components/html.html
    However, to integrate a browser you need 3rd party software like IceBrowser
    If you Google for: HTML Swing
    then you find many more hints
    Frank

  • How to call gnuplot command from java

    Hi there,
    In our course, we are required to develop an GUI for gnuplot. In case you don't know about gnuplot, it's a plotting program and has lots of command. We want to use java and swing, but now we don't know how to call gnuplot command from java, or how to execute a shell command(script) from java.
    By the way, since we need read in files with several columns of data and allow user to select a column, we want to use JTable. Is that reasonable?
    Thanks a lot for any suggestions!
    Jack

    Hi, there:
    Will using JTable add much overhead? I may have to use several JTables and switch among them. I can add scroll bar to or edit JTables, right?
    BTW, do you have experience about gnuplot? Can I find the command tree of gnuplot somewhere? Or do you know a better place to post question about gnuplot? unix/linux group, maybe.
    Thanks,
    Jack
    P.S. Would you guys answer my question after I use up my duke dollars? :- )

  • How to call Jakarta Ant via JAVA?

    Hi.
    My application has a new menu. This menu creates a build.xml Ant file.
    Now, when this menu is invoked , its action should call
    Jakarta Ant, after creating the xml file, so that the build.xml will
    do what is necessary.
    How can I do it? That is, how to call the Ant via java?
    Is there any way to use an Ant object?
    Thanks?
    Rodrigo Pimenta Carvalho.

    There is a slight problem in that
    PorjectHelper.configureProject is deprecated, but
    that is what Main calls...maybe someone else will
    complete this thread with an alternative call.The javadoc recommends using the non static method parse() instead. This is available by implementing class ProjectHelperImpl. An alternative to the code above might look like this:
            Project ant = new Project();
            ProjectHelper helper = new ProjectHelperImpl();
            ant.init();
            helper.parse(ant, new File("build.xml"));
            ant.executeTarget("clean");you might also want to add a logger so you can see the output of events generated by ant. The DefaultLogger class would be used like this. Simply add the code before you call the ant.init().
            DefaultLogger log = new DefaultLogger();
            log.setErrorPrintStream(System.err);
            log.setOutputPrintStream(System.out);
            log.setMessageOutputLevel(Project.MSG_INFO);
            ant.addBuildListener(log);

  • How to use quartz to integrate a standalone application in a webserver

    Can anyone help me in using quartz where i need to integrate a java standalone application into the webserver..I am developing an application using jsp and as part of a task i had created a standalone application in java and now i need to integrate this standalone application into the webserver because it needs to run as a webapplication.

    Hai sam,You gave us many valuable suggestions in the past.We tried all of those methods to make our application run as per scheduled but we failed.We have not yet tried the servlet method,which you suggested in your last reply. Actually we tried to use the os scheduler for this purpose and couldn't do it at the end.So can you suggest the way in which we have to write the servlet and invoke it. We dont need all the details.Just give us the idea of what this servet contains actually and how it works.We will try to do it.Thank you,

  • Creating a user in EP using a java standalone application

    Hi,
      I am trying to create a java application to create a user in Enterprise Portal.
      I am getting the following error:
    com.sap.security.api.UMRuntimeException: Cannot lookup ManageConnectionFactory "jdbc/sapep". Possible reasons: 1) The connector in which ManagedConnectionFactory "jdbc/sapep" is defined is not deployed or not started, 2) Cannot deserialize object due to a naming exception.
    ume.db.connection_pool_type=jdbc/sapep
    ume.db.connection_pool.j2ee.xatransactions_used=false
    ume.db.connection_pool.j2ee.is_unicode=true
    ume.db.connection_pool.j2ee.oracle_native_driver_used=false: Cannot lookup ManageConnectionFactory "jdbc/sapep". Possible reasons: 1) The connector in which ManagedConnectionFactory "jdbc/sapep" is defined is not deployed or not started, 2) Cannot deserialize object due to a naming exception.
      Q1. Is it possible to create user from java standalone application.
      Q2. Pls. help to resolve the error or give any sample code if you have
      Thanks in advance.
    Regards,
      Pratik

    Hi Ravi,
    How about something like this:
    IUserMaint user = UMFactory.getUserFactory().newUser("myNewUser");
    user.setFirstName("1st Name");
    user.setLastName("2nd Name");
    user.setEmail("[email protected]");
    user.save();
    user.commit();
    IUserAccount uacc = UMFactory.getUserAccountFactory().newUserAccount("myNewUser", user.getUniqueID());
    uacc.setPassword("initial");
    uacc.setPasswordChangeRequired(false);
    uacc.save();
    uacc.commit();
    Hope this helps.
    Daniel

  • How to avoid directory listing in java web applications.

    how to avoid directory listing in java web applications.
    That is on typing the url of the application it should not the directory listing. Welcome tag in web.xml doesnot fully solve the problem, since still the images folder etc is still accessible

    I know of two ways.
    If you're using tomcat and have access to the conf directory.
    Edit your $TOMCAT/conf/web.xml. Find your default servlet properties and change
      <servlet>
        <servlet-name>default</servlet-name>
        <servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
        <init-param>
          <param-name>debug</param-name>
          <param-value>0</param-value>
        </init-param>
        <init-param>
          <param-name>listings</param-name>
          <param-value>true</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
      </servlet>to  <servlet>
        <servlet-name>default</servlet-name>
        <servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
        <init-param>
          <param-name>debug</param-name>
          <param-value>0</param-value>
        </init-param>
        <init-param>
          <param-name>listings</param-name>
          <param-value>false</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
      </servlet>And restart your server. This will affect every directory on the server, and return a 405 directory browsing forbidden error.
    Another way, is to place an index.jsp inside each directory with a simple one line redirect to your applications CONTEXT_PATH.response.sendRedirect("http://yourserver/yourapp/");This will only affect specific directories which contain these index.jsp files.
    Hope this helps

  • Integrate Java standalone application when WIndows start

    Hello everybody.I would like to ask you if it is possible to load a Java standalone application when any Windows platform (NT/2000/98/XP) starts.
    How can I integrate an application when WIndows start?Do I have to include the bat file(which callls the java applictaion) into a Windows system file?
    Regards.

    You can do one of several things:
    1. Write a native executable that runs the Java Archive (JAR) using the java shell command.
    2. Write a Windows shortcut that runs the java shell command (again passing in the JAR).
    3. Purchase software that will produce a native executable that will run the JAR for you.
    4. Integrate JAR files as executable programs into your Kernel. In Windows this is not easy, but again, there are solutions on the Internet, but you will most likely have to purchase these.
    5. Configure the JAR file type so that when any JAR file type is double-clicked (and the default action is performed), the Java runtime is executed with the JAR as a parameter.
    5 is my usual solution, and for operating systems like Linux, and especially MacOS, it is much easier to get JARs to run 'more natively'.
    The answer to your question is simply 'Yes' but it is your choice of how to do this.
    As far as running the JAR when your desktop starts up (Explorer in this case), you can do two things - firstly there's a 'Run' item in your registery where you can place the location of your shortcut / executable, secondly, you can simply put the short-cut or the executable (I recommend a shortcut) in your 'Startup' folder of your Start Menu. (Start -> Programs -> Startup).
    I hope this helps.
    Gen.
    http://www.opetec.com/

  • Idea ? web interface + java standalone application

    Hello,
    I would provide a java standalone application. In parallel, I want create web interface (HTML+CSS+JS) that can write configuration files and read output files.
    Can I avoid the use of tomcat server ? May be, I know nice solution like jetty : is-it difficult ?
    Anyway, I'm looking for any piece of advice ..
    Thanks,
    From France
    Edited by: phpvik on May 4, 2009 8:10 AM

    What are the technical requirements? Just choose the server based on that.

  • How to call a servlet from another servlet

    hi everybody,
    i have a problem, i have to call one servlet from another one.
    Everything works on my pc, but when i install the application on the customer's server i got an error about an Uknown URL followed by the name of the machine.
    Wjat i do is the folloqing :
    String urlString = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+"/"+servletName;
    URL url = new URL(urlString);
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    the variable servletName is the name of the servlet i have to call.
    Is there another way to call the servlet ?
    All the servlet are installed in the same server.
    Any suggestion ?
    Cheers.
    Stefano

    Sweep is correct about requestDispatcher being another approach for inter-servlet delegation; the only issue that i recall with this approach is that it defaults the method of the destination servlet to the one it was called from...for example, calling servlet2 from within servlet1.post() resulted in the dispatcher attempting to utilize servlet2.post() - i believe that i searched for a parameterize solution to no avail :( (ended up handling the request by placing a "fake" doPost() in servlet2 that simply called servlet2.doGet())
    however, if your application is functioning correctly on your pc/webserver then the problem may be external to servlet communication (e.g. client webserver's ports not configured or blocked, missing runtime classes, etc.)
    my suggestion would be to set aside the programmatic concerns for the moment - what is the response if you open a browser on a client's machine and access the URL in question (i.e. http://clientserver:port/stefanoServlet)? If it will not respond to access in this manner then it certainly won't when your application calls for it.
    It's possible that there is a coding error but, given the info supplied, i'd start examining the environment, first. Let us know if you have any luck with the test i recommended or not (please provide abundant detail). Or, if you've found the solution then you may want to post back with a quick blub so the next person knows how to escape the trap.
    D

Maybe you are looking for