Calling Servlet from a java prog?

Hi all,
I am calling servlet from a java prog (Java Agent in Lotus Notes) by using URL and URLConnection object. how can i trigger the Servlet By using doPost method .I have to send some parameter also.
Thanx
Muthu

you need to open a connection to the servlet. Then you must call getInputStream() and getOutputStream() and use them in any way you see fit. I was trying this before and could not get POST to work unless I openned the input stream from the servlet. Strange... but doGet worked without openning the input stream???
// open a connection....
// write to the servlet
servletConnection.getOutputStream().write("whatever");
servletConnection.getOutputStream().flush();
servletConnection.getOutputStream().close();
// grab what the servlet sends back, required to do a post.
byte [] in = new byte[100];
servletConnection.getInputStream().read(in);
servletConnection.getInputStream().close();

Similar Messages

  • Calling servlet from a java program

    Hi
    I need to call a servlet's doPost() method from a java program. I have a specific situation, where I need to call servlet from a java program. DUring this call I need to pass a file and two string to the servlet. Servelt after receiving the file and string uploads the file to the server at a specified location. I am stuck up as how to call servlet from a java program instead of a HTML or JSP.
    Can anyone help me to start with this.
    any suggestion is welcome.

    You have to establish a URLConnection with servlet from your java program.
    URL servletURL = new URL("http://localhost:8080/Myservlet?str1=abc&str2=def");
    URLConnection servletConnection = servletURL.openConnection();you can get the objectOutputStream
    ObjectOutputStream oos = new ObjectOutputStream (servletConnection.getOutputStream());
    oos.writeObject(your file object);-------------------------------------------------
    In the servlet u can get the strings using request.getParameter("str1");
    In the servlet u can get the strings using request.getParameter("str2");
    file = new ObjectInputStream (request.getInputStream()).readObject()a lot of resources are available on this ...
    hope this helps :)

  • Calling Servlet from a java class

    Hi,
    I don�t know what I�m doing wrong...
    I try to call a servlet located in a tomcat webserver, from a class, and capture its output. I use an URLConnection object... Everything is all right when I want to get an html page, but, it reports an IOException (FileNotFoundException) when the requested resource is a servlet.
    This servlet is working correctly.
    Can�t I use an URLConnection to access servlets?
    Cheers

    try setting up the user agent property of HTTP protocol to a browsers,its worth a shot.
    Cheers
    Khalid

  • Is it possible to call a method in a servlet from  a java script ?

    I need to do a dynamic html page . In the page i select some things and then these things must communicate whit a servlet because the servlet will do some DB querys and update the same webpage.
    So is it possible to actually call a method of a servlet from a java script? i want to do something that looks like this page:
    http://www.hebdo.net/v5/search/search.asp?rubno=4000&cregion=1011&sid=69DHOTQ30307151
    So when u select something in the first list the secodn list automaticly updates.
    thank you very much

    You can
    1. load all the options when loading the page and
    set second selection options when user selected
    the first; or
    2. reload the page when user select first selection
    by 'onChange' event; or
    3. using iframe so you only need to reload part of
    the page.

  • Calling a servlet from a Java Stored Procedure

    Hey,
    I'm trying to call a servlet from a Java Stored Procedure and I get an error.
    When I try to call the JSP-class from a main-method, everything works perfectly.
    Java Stored Procedure:
    public static void callServlet() {
    try {
    String servletURL = "http://127.0.0.1:7001/servletname";
    URL url = new URL(servletURL);
    HttpURLConnection conn = (HttpURLConnection)url.openConnection();
    conn.setDoOutput(true);
    conn.setRequestProperty("Pragma", "no-cache");
    conn.connect();
    ObjectInputStream ois = new ObjectInputStream(conn.getInputStream());
    Integer client = (Integer)ois.readObject();
    ois.close();
    System.out.println(client);
    conn.disconnect();
    } catch (Exception e) {
    e.printStackTrace();
    Servlet:
    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    Integer id = new Integer(10);
    OutputStream os = response.getOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(os);
    oos.writeObject(id);
    oos.flush();
    oos.close();
    response.setStatus(0);
    Grant:
    call dbms_java.grant_permission( 'JAVA_USER', 'SYS:java.net.SocketPermission','localhost', 'resolve');
    call dbms_java.grant_permission( 'JAVA_USER','SYS:java.net.SocketPermission', '127.0.0.1:7001', 'connect,resolve');
    Package:
    CREATE OR REPLACE PACKAGE pck_jsp AS
    PROCEDURE callServlet();
    END pck_jsp;
    CREATE OR REPLACE PACKAGE BODY pck_jsp AS
    PROCEDURE callServlet()
    AS LANGUAGE JAVA
    NAME 'JSP.callServlet()';
    END pck_jsp;
    Architecture:
    AS: BEA WebLogic 8.1.2
    DB: Oracle 9i DB 2.0.4
    Exception:
    java.io.StreamCorruptedException: InputStream does not contain a serialized object
    at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java)
    at java.io.ObjectInputStream.<init>(ObjectInputStream.java)
    The Servlet and the class work together perfectly, only when I make the call from
    within the database things go wrong.
    Can anybody help me.
    Thank in advance,
    Bart Laeremans
    ... Desperately seeking knowledge ...

    Look at HttpCallout.java in the following code sample
    http://www.oracle.com/technology/sample_code/tech/java/jsp/samples/jwcache/Readme.html
    Kuassi

  • Erase a file from a java prog?

    Hello.
    Is it possible to erase an image in a directory from a java program? Or do I have to create a shell script that I call in the java program?
    I saw somewhere on the web that it wasn't possible to call a shell script from a java prog, so if there's a method in java that does it, I would be glad to know it. Any help would be appreciated.
    Many thanks
    Philippe

    thanks, guys.
    But I get a io.FilePermission... with the two methods.
    I checked my permissions, and it's all right
    what's happening?What do you mean by "I get a io.FilePermission" ?
    What exactly do you get ?
    Which two methods are you talking about ?
    If the file can't be deleted the file may be used by another ( hanging) process.

  • 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.

  • Calling servlets from main()?

    Hi
    I would like to know that while calling servlets from another class having main(), how can we set the type of request i.e. put, post or get?
    Thanks

    use the method - setRequestMethod( "POST") of HttpURLConnection for setting the method to POST.Similarly for other methods..
    You could find [url http://java.sun.com/developer/JDCTechTips/2004/tt0210.html#2]this useful

  • Wot all ways are there to call servlet from jsp

    hi all
    i want to know wot all methods are available
    so that i can call servlet from jsp
    the one which i know is using RequestDispatcher
    wot are others ?
    thanx

    hi all
    i want to know wot all methods are available
    so that i can call servlet from jsp
    the one which i know is using RequestDispatcher
    wot are others ?
    thanxhi here are few ways... to call servlet from jsp...
    these are just generic syntax.
    Form:     
    <form action="ServletPath">
    Link:     
    Directives & Action tags :
    <%@ page import="ServletPath" %>
         <%@ taglib uri="ServletPth" %>
         <jsp:include page="ServletPath">
         <jsp:forward page="ServletPath">
         <jsp:useBean class="ServletPath"> (Not sure about this useBean)
    hope you got your answer.
    regards,
    immu

  • Example-- Call RFC from external Java Application

    Update: I need code example to call RFC from External Java application. Can onybody help me?                                                      
    RGDS
    RP
    hi all.
    i want to create my own log for each interface.
    i saw this blog:
    /people/michal.krawczyk2/blog/2006/09/20/xi-abap-mapping-logs--more-standard-better-visibility
    my doubt is how to catch the error that i see in SXI_MONITOR y put it in a Sub-Objetc.
    For example: in sxi_monitor i get the error for my interface NMUCustomer: "No receiver could not be found" or "Error Mapping Traformation".
    I created an Object called ZNMUCUSTOMER and a Sub-Objetc called ZERROR.
    what i must do to get the error I see in monitor and assign it to Sub-Object??
    Rgds.
    Message was edited by:
            Rodrigo Pertierra
    Message was edited by:
            Rodrigo Pertierra
    Message was edited by:
            Rodrigo Pertierra

    Hi,
    Oh, you are using ABAP mapping ......
    then use the following in ABAP mapping ..
    TRACE1,TRACE2,TRACE3.... for trace level 1,2,3......
    http://help.sap.com/saphelp_nw04/helpdata/en/ba/e18b1a0fc14f1faf884ae50cece51b/content.htm
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/5c46ab90-0201-0010-42bd-9d0302591383
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/866ce290-0201-0010-338f-b8c3553aaa0f
    Regards
    Chilla

  • Calling JPA from a Java Stored Procedure

    Is it possible to call JPA from a java stored procedure? If so, does anyone have example? How do you setup the persistence.xml?
    How does the peformance compare with straight JDBC in a java stored procedure?
    Thanks for any help!
    Johnny

    Hi Johnny:
    Basically you can run any JDK 1.5 framework inside your Oracle 11g JVM, I have experience integrating Lucene IR library as a new [Domain Index for Oracle 11g/10g|http://docs.google.com/View?id=ddgw7sjp_54fgj9kg] .
    I am not familiar with JPA internals but my advice is howto handle the connection inside the OJVM and the configuration files.
    Some time ago I took a look to SpringFramework integration and I found that writing a new ApplicationContext class which handles the loading of beans.xml from XMLDB repository instead a file should be enough to work.
    Another important point is the life cycle of the [Oracle internal JVM|http://download.oracle.com/docs/cd/E11882_01/java.112/e10588/chtwo.htm#BABHGJFI]. Unlike an standard JVM the OJVM is created once you first connect from the middle tier at OCI level and remains in execution during the connection pool existence.
    I mean, if you connect using a JDBC pool the JVM will remains running across multiple soft open/close connections of your middle tier application. This is good because you can read your persistence.xml file using a Singleton class and this expensive operation will be re-used by multiple open/close operation done from the middle tier.
    I suggest you do a simple Proof of Concept with a Hello World application and check if it works.
    Remember that any security issues will be notified to the .trc files, security issues are related to the strong security layer configured by default inside the OJVM, for example you can not read any files from the OS file system without an specific grant, you need another grant to access to the class loader and so on, but you can simply grant this specific needs to a database role and then grant this role to the user which connect to the OJVM.
    Another important point is related to the [End-of-Call Optimization|http://download.oracle.com/docs/cd/E11882_01/java.112/e10588/chtwo.htm#BABIFAAI] this can be useful if you want to perform some clean up in your Singleton class at the level of per-statement execution.
    Best regards, Marcelo

  • Problem while calling servlet from java bean

    I am trying to call a servlet from java bean in cep.
    My java bean:
    package com.bea.wlevs.example.algotrading;
    import com.bea.wlevs.ede.api.StreamSink;
    import com.bea.wlevs.example.algotrading.event.MarketEvent;
    import javax.xml.bind.JAXBContext;
    import javax.xml.bind.Unmarshaller;
    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.io.OutputStreamWriter;
    import java.io.StringReader;
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.net.URLConnection;
    public class MarketEventBean implements StreamSink {
         String s=null;
         public void onInsertEvent(Object event) {
              if (event instanceof MarketEvent) {
                   MarketEvent marketEvent = (MarketEvent) event;
                   try {
                        JAXBContext cxt = JAXBContext.newInstance(MarketEvent.class);
                        Unmarshaller unmarsh = cxt.createUnmarshaller();
                        StringReader strReader = new StringReader(marketEvent.getString_1());
                        MarketEvent obj = (MarketEvent) unmarsh.unmarshal(strReader);
                        s=obj.getSymbol();
                        System.out.println("data: " + s);
                   } catch(Exception e) {
                        e.printStackTrace();
                   try {
                        System.out.println("test1");
         URL url = new URL("http://172.18.21.94:7001/AppServletrecv-Model-context-root/ReceiveServlet");
         URLConnection conn = url.openConnection();
              System.out.println("test2");
         conn.setDoOutput(true);
              System.out.println("test3");
         BufferedWriter out =
         new BufferedWriter( new OutputStreamWriter( conn.getOutputStream() ) );
         out.write("symbol="+s);
              System.out.println("test4");
         out.flush();
         System.out.println("test5");
         out.close();
         System.out.println("test6");
         BufferedReader in =
         new BufferedReader( new InputStreamReader( conn.getInputStream() ) );
              System.out.println("test7");
         String response;
         while ( (response = in.readLine()) != null ) {
         System.out.println( response );
         in.close();
         catch ( MalformedURLException ex ) {
         // a real program would need to handle this exception
         catch ( IOException ex ) {
         // a real program would need to handle this exception
    My servlet code:
    package model;
    import javax.servlet.http.HttpServlet;
    import java.io.IOException;
    import java.io.PrintWriter;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    public class ReceiveServlet extends HttpServlet {
    private final static String _SYMBOL = "symbol";
    public void doPost(HttpServletRequest request, HttpServletResponse response) {
    * Get the value of form parameter
    // private final static String USERNAME = "username";
    String symbol = request.getParameter( _SYMBOL );
    * Set the content type(MIME Type) of the response.
    response.setContentType("text/html");
    * Write the HTML to the response
    try {
    PrintWriter out = response.getWriter();
    out.println("<html>");
    out.println("<head>");
    out.println("<title> A very simple servlet example</title>");
    out.println("</head>");
    out.println("<body>");
    out.println("<h1>Hello " + symbol +"</h1>");
    out.println("</body>");
    out.println("</html>");
    out.close();
    } catch (IOException e) {
    Web.xml:
    <?xml version = '1.0' encoding = 'windows-1252'?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    version="2.5" xmlns="http://java.sun.com/xml/ns/javaee">
    <servlet>
    <servlet-name>ReceiveServlet</servlet-name>
    <servlet-class>model.ReceiveServlet</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>ReceiveServlet</servlet-name>
    <url-pattern>/ReceiveServlet</url-pattern>
    </servlet-mapping>
    </web-app>
    My servlet is running in weblogic server.
    But when I am running this program in weblogic server side there is no log.
    Edited by: 856272 on Jun 23, 2011 6:43 AM

    I would run both sides in a debugger and see what code is getting invoked

  • Calling servlet from java page flow

    Hi,
    I need to call servelt class from the <netui:anchor ..> tag of my jpf.
    i have mapped this servlet class in the web.xml.
    please tell us how to invoke servlet from the netui:anchor tag from the jpf action
    method.
    thanks
    shashi

    I am calling a Servlet from JAVA Class as I am using IDE: Eclipse. The Problem is below
    URL url = new URL(ServletPath);
    URLConnection connet = url.openConnection();Why should the Servlet running in different Runtime print on your Eclipse Runtime. Please be more clear about the question.

  • Calling servlet from Java

    Hello!
    I need to send XML file to servlet from Java. I generate XML in general java class.
    Is there any way how to call servlet directly from Java without using a page with form? I need to send it by post method. I need some java alternative to Microsoft.XMLHTTP object.
    Thanks

    Try this part of the Networking tutorial:
    http://java.sun.com/docs/books/tutorial/networking/urls/index.html
    It might be the answer to your question.

  • Calling Servlet from Java Class in eclipse

    Hi ,
    I am calling a Servlet from JAVA Class as I am using IDE: Eclipse. The Problem is below
    URL url = new URL(ServletPath);
    URLConnection connet = url.openConnection();
    I am using the above code in JAVA to Connect to Servlet I have given Print statement in Servlet such that whenever it calls it prints on Console but when I try to run the code the Statement is not printed in the Console of eclipse I think URL connection is not able to establish any connection ..... if any has solution for this please reply
    Thanks & Regards,
    Arvind

    I am calling a Servlet from JAVA Class as I am using IDE: Eclipse. The Problem is below
    URL url = new URL(ServletPath);
    URLConnection connet = url.openConnection();Why should the Servlet running in different Runtime print on your Eclipse Runtime. Please be more clear about the question.

Maybe you are looking for

  • Financial Reporting - Planning 11.1.2.1 Data Source

    We are trying to do salary planning, specifically new hire planning at an employee level. Is it possible to have an account of data type text that users could input into a form, and then build reports in Financial Reporting Studio that would display

  • TS3276 Content-Transfer-Encodong: quoted-printable?

    Does anyone know why I'm receiveing emails that look like this? Is it a setting on my end or the sending emailer? Thanks in advacne for your help. --Apple-Mail-425-337390284 Content-Type: multipart/mixed;           boundary=Apple-Mail-426-337390286 -

  • How to manually generate events in SMC 3.5 ?

    Dear, We are using the SDK of SMC 3.5 to build an application. To test the application, how can we generate events manually ? I'd like to have a script on Solaris that, when run, generates an event in the SMC database. Does anyone have such a script

  • Palm TX sync errors

    ++Hello all,++ ++Can anyone explain this iSync generated error message when I perform a hotsync using Missing Sync 5.1.2? I am trying to syncronize Palm Calendar, Contacts, and Task with Mac iCal, Address, and To-Do's.++ ++Saturday, October 20, 2007

  • Create a vizualization of artwork

    Hi, i created seveeral business cards and other artworks in Illustrator cs5. I was wondering if Illustrator can generate a vizualization of business cards (for example) like if it was a real PRINTED business card and place on table ? if not, do you k