How can I call a servlet method from a javascript function

I want to call l a servlet method from a javascript function.
Does any one have an example of code.
Thinks in advance

Actually, as long as the servlet returns valid javascript, you can indeed "call it" from the client. It will initiate a request and return the result to the browser.
This example uses Perl, but it could be easily modified to go to a servlet instead.
Note that it is only supported in DOM browsers (IE6+/NN6+/etc)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<title> Test server-side JS </title>
</head>
<body>
<script type="text/javascript">
function checkIt(variable, value)
var newScript = "cgi-bin/validateJS.cgi?"+variable+"="+value;
var body = document.getElementsByTagName('body').item(0)
var scriptTag = document.getElementById('loadScript');
if(scriptTag) body.removeChild(scriptTag);
script = document.createElement('script');
script.src = newScript;
     script.type = 'text/javascript';
     script.id = 'loadScript';
     body.appendChild(script)
</script>
<p>Test.</p>
<form id="f1" action="">
<input type="text" name="t1" id="t1" onChange="checkIt(this.name, this.value)">
</body>
</html>
validateJS.cgi
#!/opt/x11r6/bin/perl
use CGI qw(:all);
my @valArray = split(/=/,$ENV{QUERY_STRING});
print "Content-type: text/javascript\n\n";
# myPass is the password
$myPass = "foobar";
if ("$valArray[1]" eq "$myPass")
print "alert(\"Success!!\")";
else
print "alert(\"Failure!!\")";

Similar Messages

  • How can I call  a component method from OCAP ?

    I'll try to invoke Cold Fusion Component from Xlet (OCAP App), specifically I wan to invoke a query from Component(CFC) method.
    Somebody knows how to... or any idea or comments.
    Thank you so much!

    Actually, as long as the servlet returns valid javascript, you can indeed "call it" from the client. It will initiate a request and return the result to the browser.
    This example uses Perl, but it could be easily modified to go to a servlet instead.
    Note that it is only supported in DOM browsers (IE6+/NN6+/etc)
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
    <html>
    <head>
    <title> Test server-side JS </title>
    </head>
    <body>
    <script type="text/javascript">
    function checkIt(variable, value)
    var newScript = "cgi-bin/validateJS.cgi?"+variable+"="+value;
    var body = document.getElementsByTagName('body').item(0)
    var scriptTag = document.getElementById('loadScript');
    if(scriptTag) body.removeChild(scriptTag);
    script = document.createElement('script');
    script.src = newScript;
         script.type = 'text/javascript';
         script.id = 'loadScript';
         body.appendChild(script)
    </script>
    <p>Test.</p>
    <form id="f1" action="">
    <input type="text" name="t1" id="t1" onChange="checkIt(this.name, this.value)">
    </body>
    </html>
    validateJS.cgi
    #!/opt/x11r6/bin/perl
    use CGI qw(:all);
    my @valArray = split(/=/,$ENV{QUERY_STRING});
    print "Content-type: text/javascript\n\n";
    # myPass is the password
    $myPass = "foobar";
    if ("$valArray[1]" eq "$myPass")
    print "alert(\"Success!!\")";
    else
    print "alert(\"Failure!!\")";

  • How can i call a taskflow methode from backing bean ??

    Build JDEVADF_11.1.1.3.PS2_GENERIC_100408.2356.5660
    i like to call a Methode (taskflow) from backing bean!
    my bean code :
        public void imageLinkActionListner(ActionEvent actionEvent) {
            String              id      = actionEvent.getComponent().getId();
            int                 linkID  = Integer.parseInt(id.substring(4));
            DCBindingContainer  bc      = (DCBindingContainer)ADFUtils.getBindingContainer();
            DCTaskFlowBinding   tf      = null;
            System.out.println("Region Change...."+id+" INT "+linkID);
            switch (linkID) {
                case LINK_CALENDAR_REGION:
                    tf = (DCTaskFlowBinding)bc.findExecutableBinding("calendartaskflowPage");                   
                break;
                case LINK_MAIL_REGION:
                    tf = (DCTaskFlowBinding)bc.findExecutableBinding("mailtaskflowPage");                   
                break;
              case LINK_ADDRESS_REGION:
                  tf = (DCTaskFlowBinding)bc.findExecutableBinding("addresstaskflowPage");                   
              break;
              case LINK_BLOGS_REGION:
                  tf = (DCTaskFlowBinding)bc.findExecutableBinding("blogstaskflowPage");                   
              break;
              case LINK_MAPS_REGION:
                  tf = (DCTaskFlowBinding)bc.findExecutableBinding("mapstaskflowPage");                   
              break;
            default:
                return;
            if (tf != null){
                uiMainRegion.setRegionModel(tf.getRegionModel());
                uiMainRegion.setValue(tf.getRegionModel());
                tf.getExecutableBindings();
                AdfFacesContext.getCurrentInstance().addPartialTarget(uiMainRegion);
        }i like to call *#{backingBeanScope.mapBean.initMap}*
    my taskflow source
    <?xml version="1.0" encoding="windows-1252" ?>
    <adfc-config xmlns="http://xmlns.oracle.com/adf/controller" version="1.2">
      <task-flow-definition id="map-task-flow">
        <default-activity id="__1">map</default-activity>
        <view id="map">
          <page>/map/map.jsff</page>
        </view>
        <method-call id="initMap">
          <method>#{backingBeanScope.mapBean.initMap}</method>
          <outcome id="__7">
            <fixed-outcome>init</fixed-outcome>
          </outcome>
        </method-call>
        <control-flow-rule id="__2">
          <from-activity-id id="__3">initMap</from-activity-id>
          <control-flow-case id="__5">
            <from-outcome id="__6">init</from-outcome>
            <to-activity-id id="__4">map</to-activity-id>
          </control-flow-case>
        </control-flow-rule>
        <use-page-fragments/>
      </task-flow-definition>
    </adfc-config>

    Hi,
    to call the bean, use the EL in Java and reference #{backingBeanScope.mapBean.initMap} as a method expression. If you try and access the bean directly then chances are that the instance is not available. Using EL from Java always guarantees this
    Frank

  • How can i call a main method  from a different class???

    Plzz help...
    i have 2 classes.., T1 and T2.. Tt2 is a class with a main method....i want to call the main method in T2......fromT1..is it possibl..plz help

    T2.main(args);

  • How can I call the create method in BO from Application Service

    Hello!
    When I create a Business Object, CAF generates some methods automatically.
    How can I call the create method in the BO from Application Service logic?
    When i call the method then the entityManager and the sessionContext is NULL.
    How can I initialize this?
    Can anybody help me?
    Thanks, Thomas

    If you are using CE 7.11...
    1) In the Application Services, add the BO as dependant object in dependencies tab.
    2) In the implemention, add the following codes to call create method of the BO:
    this.get<BO>.createMethod();
    julius

  • How can i call mouse click event from keypress event???

    How can i call mouse click event from keypress event???
    I want same GUI changes to be occured at key press.....i.e . button going down & comming up.....
    for calculator

    Put all the code that happens on those events into a method. Then call that method from both events.

  • Can any one tell me how can i call a shell script from pl/sql

    i like to call shell script from pl/sql procedure.
    can any one suggest how can i do this

    Have you not mastered in asking the same kind of question ?
    First do write a script...
    no one will spoon feed you.
    How can i call a shell script from procedure
    How to call Shell Script from pl/sql block
    -Sk

  • How can i call a shell script from procedure

    I have a shell script.now i am i a situation to call that shell script from one of my procedures and need to get a value from that script.
    can u suggest me that how can a call the shell script from pl/sql?

    Is the same question you asked here
    How to call Shell Script from pl/sql block
    -SK

  • How can i call Apple in usa from Egypt to buy an iPhone from Apple store please who khnow the contacting number answer me :)

    how can i call Apple in usa from Egypt to buy an iPhone from Apple store please who khnow the contacting number answer me

    http://www.apple.com/eg/buy/
    There are three companies linked to towards the bottom right to purchase an iPhone from. Above those three is Arab Business Machine. Choose one, or check each one out.

  • How can i call forpro prg file from java

    Hai friends,
    I have a doubt,clear it.
    how can i call forpro prg file from java file
    by,
    N.Vijay

    Thanks to your reply,
    I have some print statements in my foxpro program file.
    Then i like to invoke that foxpro file from my java file
    This want i want..,
    by,
    N.Vijay

  • How can I call a servlet from a javascript

    Hello
    I have a JSP page that has 2 aim : save and list. I want to use javascript like this to call my save and list methods :
    <SCRIPT language="JavaScript">
    function savedata(){
    document.kaydetsorgula.action = "hatBilgisiKaydetKontroller.java";
    document.kaydetsorgula.submit();     
    function listdata(){
    document.kaydetsorgula.action = "hatbilGoruntulemeKontroller.java";
    document.kaydetsorgula.submit();     
    </SCRIPT>
    I use this js in my JSP, hatBilgisiKaydetKontroller.java and hatbilGoruntulemeKontroller.java are my servlets names.In servlets I call the methods of sessions.
    Also in my JSP I use
    <tr>
    <td colspan=9 align=center>
    <input type="submit" value="Kaydet" >
    <input type="submit" value="Sorgu">
    </td>
    </tr>
    code to call the js.
    But my code does not work?
    Does anyone have any idea?
    Thanks
    ANIL

    Thanks.....
    I could manage to work it by using <input type="submit" value="Sorgu" onClick="sorgula()"> ...
    And know I have another problem...
    I have a listing page.This pages shows data from a database table and in this table there are 100 rows but I want to show data 10 by 10.I mean when I click on next link I want to see the other 10...
    My JSP code is like this :
    <%@ page contentType="text/html;charset=windows-1254"%>
    <%@ page import="java.util.*"%>
    <%@ page import="java.lang.*"%>
    <% Context context = new InitialContext();
    DataSource ds = (DataSource) context.lookup("jdbc/DUKSDS");
    Connection conn = ds.getConnection();
    Statement stmt = conn.createStatement();
    stmt.executeQuery("select rownum,hatKodu,hatAdi from HATBIL where rownum < 11 order by hatkodu");
    String vhatKodu = request.getParameter("hatKodu");
    ResultSet rs = stmt.getResultSet();
    ResultSetMetaData rsmd = rs.getMetaData();
    %>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1254">
    </head>
    <SCRIPT language="JavaScript">
    function sonrakikayitlar(){
    document.listelemeekrani.action = "listeleme.jsp";
    document.listelemeekrani.submit();     
    </SCRIPT>
    <body>
    <img src="file:/C:/DUKS/ERD Logo.gif" width="100" height="100">
    <H2><center>DEMIR URETIM KONTROL SISTEMI</center> </H2>
    <br>
    <H3><center>HAT BILGISI LISTELEME EKRANI</center> </H3>
    <center><input type="hidden" name="hiddenField">
    <form name="listelemeekrani" method="get">
    <table class="clsScroller" cellspacing="2" cellpadding="3">
    <tr>
    <td>Previous</td>
    <td align="center">
    <select>
    <option selected value="1">1-2 of 2</option>
    </select>
    </td>
    <td>Next</td>
    </tr>
    </table>
    <table border="1">
    <tr>
    <td align="center" colspan="5" >HAT KODU</td>
    <td align="center" colspan="5">HAT ADI</td>
    </tr>
    <%
    while (rs.next()) {
    %>
    <tr>
    <td bgcolor="pink" colspan="5"><%=rs.getString("hatKodu")%></td>
    <td bgcolor="pink" colspan="5"><%=rs.getString("hatAdi")%></td>
    <!-- <td bgcolor="pink" colspan="5"><%=vhatKodu%></td>-->
    </tr>
    <%
    rs.close();%>
    </table>
    <% System.out.println(rsmd.getColumnCount()); %></p>
    BILGI GIRIS EKRANI
    </table>
    </form>
    </body>
    </html>
    How?
    Thanks
    ANIL

  • How can i call a servlet from a servlet ?

    Hello,
    Can i call a Servlet from within a Servlet ?
    and is it "right thing" to Do ?
    Thanks

    JMO, but I wouldn't do it like this.
    Don't have a remote object like a servlet doing database queries for your app. That will mean TWO network hops for every query if the database resides on another machine. The network is the biggest bottleneck you've got.
    Write a JavaBean that does the database stuff for you and just have the first servlet instantiate it when it needs it. A Bean has a better chance of being reused, too. Write a TableGateway or DAO for your object.
    Or write an EJB to do it.
    The only time I've done a servlet-to-servlet connection like that was for one servlet running in a DMZ that would authenticate a user and then forward the request to another servlet running inside the second firewall.
    I wouldn't encapsulate database query logic in a servlet like that. JMO - MOD

  • Calling a servlet method from another class

    hi...
    if i make a servlet (that keeps the log for website users' logins and logouts, for example) and i want a method that adds an entry into a logfile, for example:
    public void log(String line) {
    //put "line" into some log file...
    and then i set this servlet to loadonstartup, how can i call the log() function from other classes or servlets? can i do it without making the servlet an entry in servletContext?
    im sorry if i'm not being very clear, the caffeine's getting to me...
    thanks
    lazlo

    I don't know, why would you do that anyway? Just make an ordinary class, not a servlet, and make "log" a static method in that class. (If you need initialization, use a static initializer.) Put that class where the real servlet can see it and call it from there.

  • How can i call a DLL file from labview?

    Iam using a sensoray 2601 module.It is given as DLL file(S2600.DLL).How can i call this function from LabVIEW?
    Please Mark the solution as accepted if your problem is solved and donate kudoes

    As far as I can tell problems might occur with the call library function node if the the DLL from visual basic is actually an ActiveX dll if that is the case it seems calling the dll by using the Invoke node is the way to go.
    Have a look at this 
    /sletten

  • How can I call a java object from Web dynpro ABAP application?

    I made Web dynpro ABAP application and posted it to SAP EP.
    For certain business purpose, we need to call external 3rd party java object using 3rd party's java api in Web dynpro application.
    Is there anybody who experienced this kind of java interface issue?
    I know Web dynpro Java environment can fully support this kind of requirement. but regarding Web dynpro ABAP, I couldn't find any clue for this.
    Any comment or suggestion would be greatly appreciated.
    Thanks,
    Raymond, ABAP Consultant

    if you have jco configured, then you can make calls to java api from ABAP .
    check out this weblog.
    /people/gregor.wolf3/blog/2004/08/26/setup-and-test-sap-java-connector-outbound-connection
    Raja

Maybe you are looking for

  • Google Maps no longer works with my S4

    Ever since I bought my S4 a few months ago I have had problems with Google Maps keeping the satellite signal, but after installing the latest software upgrade on 12/11/2014 (NG6 to NK1) it has become useless.  When I open Maps it will usually find my

  • Can't customize track information on Itunes 11.01

    This might take awhile.  A month ago, I purchased a new MBP which is running Itunes 11.01.  So, I had to redo all of my playlists.  I have well over a million different audio files/music tracks.  I download A LOT of live music from different artists.

  • Data source and credential mapping

    Hi, I need to programatically override the credentials specified in data-source's connection pool. Specifically, when getConnection() is called by the applicaiton, I would like my code to take control and supply credentials. I saw the concept of role

  • ITunes Window does not display correctly

    Hey, I've just done the update to 10.6 and now I've started iTunes again and the windows doesn't fit in m y screen... is there a utility or fix for this i already tried removing preferences from my personal directory. See picture below for a screengr

  • Get DVT Drilldown Hierarchy Data in Clickevent BackingBean

    I created a Drill down functionality for Graph as per following link, http://docs.oracle.com/cd/E16162_01/web.1112/e16181/dv_graph.htm#sthref283 My PageDef file for Graph looks as follows --->Drills from DepartmentId to ManagerName then to Employees