Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-15-2008, 08:05 AM
Member
 
Join Date: May 2008
Posts: 14
hussainzim is on a distinguished road
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>
<%! }%>
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-15-2008, 08:22 AM
Eku Eku is offline
Senior Member
 
Join Date: May 2008
Location: Makati, Philippines
Posts: 199
Eku is on a distinguished road
Here is a Sample.

This Code is in your JSP
Code:
<form action="Yourservlet?action=ButtonClicked" method="post"> <%-- Your Code Here --@> <input type="submit" value=" Ok " /> </form>
This Code is inside Yourservlet.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.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
cannot call private method from static method jon80 New To Java 3 05-07-2008 09:37 AM
Call a Method Automatically rhm54 New To Java 4 02-07-2008 09:51 AM
Unablt to call a sessionbean's business method in EJB 3.0 amitid4forum Enterprise JavaBeans 0 11-24-2007 01:03 PM
Unablt to call a sessionbean's business method in EJB 3.0 amitid4forum Enterprise JavaBeans 0 11-24-2007 01:00 PM
Call a main method from within a running program zoe New To Java 1 08-07-2007 07:16 AM


All times are GMT +3. The time now is 12:08 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org