Results 1 to 2 of 2
  1. #1
    hussainzim is offline Member
    Join Date
    May 2008
    Posts
    14
    Rep Power
    0

    Default Call Java Method

    hi..i want to call a java method written in jsp page once a button is cliked..how can i do this??below is the sample code..thank u in advance...

    <input type="button" name="btn1" value="Click">

    <%! public void testMethod()
    {%>
    <select name="select2">
    <%try{ session = request.getSession();
    List v = (List)session.getAttribute("name");
    for(Iterator it=v.iterator();it.hasNext();)
    {
    Object[] row = (Object[])it.next();
    out.println(row[0]);
    out.println(row[1]);
    str=(String)row[0];
    %>
    <option><%=str%></option>


    <%}}
    catch(Exception e)
    {}finally{}%>
    </select>
    <%! }%>

  2. #2
    Eku
    Eku is offline Senior Member
    Join Date
    May 2008
    Location
    Makati, Philippines
    Posts
    234
    Rep Power
    7

    Default

    Here is a Sample.

    This Code is in your JSP
    Java Code:
    <form action="Yourservlet?action=ButtonClicked" method="post">
    
    <%-- Your Code Here --@>
    
    <input type="submit" value="   Ok   " />
    </form>
    This Code is inside Yourservlet.java

    Java Code:
    //Inside your servlet
    String action = request.getParameter("action");
    try{
                if (action.equalsIgnoreCase(null)){
                    //Your error Handler
                }else if (action.equalsIgnoreCase("ButtonClicked"))
                { // Here is where the code that will run if the button is clicked
                } else {
                  //Your Default operation
                }
    } catch (Exception A) {
                  //Another Error Handler ^_^ 
    }
    Mind only knows what lies near the heart, it alone sees the depth of the soul.

Similar Threads

  1. cannot call private method from static method
    By jon80 in forum New To Java
    Replies: 3
    Last Post: 05-07-2008, 08:37 AM
  2. Call a Method Automatically
    By rhm54 in forum New To Java
    Replies: 4
    Last Post: 02-07-2008, 08:51 AM
  3. Unablt to call a sessionbean's business method in EJB 3.0
    By amitid4forum in forum Enterprise JavaBeans (EJB)
    Replies: 0
    Last Post: 11-24-2007, 12:03 PM
  4. Unablt to call a sessionbean's business method in EJB 3.0
    By amitid4forum in forum Enterprise JavaBeans (EJB)
    Replies: 0
    Last Post: 11-24-2007, 12:00 PM
  5. Replies: 1
    Last Post: 08-07-2007, 06:16 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •