Results 1 to 2 of 2
Thread: Call Java Method
- 05-15-2008, 07:05 AM #1
Member
- Join Date
- May 2008
- Posts
- 14
- Rep Power
- 0
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>
<%! }%>
- 05-15-2008, 07:22 AM #2
Senior Member
- Join Date
- May 2008
- Location
- Makati, Philippines
- Posts
- 234
- Rep Power
- 6
Here is a Sample.
This Code is in your JSP
This Code is inside Yourservlet.javaJava Code:<form action="Yourservlet?action=ButtonClicked" method="post"> <%-- Your Code Here --@> <input type="submit" value=" Ok " /> </form>
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
-
cannot call private method from static method
By jon80 in forum New To JavaReplies: 3Last Post: 05-07-2008, 08:37 AM -
Call a Method Automatically
By rhm54 in forum New To JavaReplies: 4Last Post: 02-07-2008, 08:51 AM -
Unablt to call a sessionbean's business method in EJB 3.0
By amitid4forum in forum Enterprise JavaBeans (EJB)Replies: 0Last Post: 11-24-2007, 12:03 PM -
Unablt to call a sessionbean's business method in EJB 3.0
By amitid4forum in forum Enterprise JavaBeans (EJB)Replies: 0Last Post: 11-24-2007, 12:00 PM -
Call a main method from within a running program
By zoe in forum New To JavaReplies: 1Last Post: 08-07-2007, 06:16 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks