• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JSP button action

 
Ranch Hand
Posts: 181
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to set separate actions for three buttons in same jsp page.How can I do it?

<tr>
           <th><input type="submit" value="Submit" name="button" /></th>
           <th><input type="submit" value="Update" name="button" /></th>
           <th><input type="submit" value="Delete" name="button" /></th>
</tr>
 
Ranch Hand
Posts: 100
2
Python Spring Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

chamini prashakthi wrote:I want to set separate actions for three buttons in same jsp page.How can I do it?

<tr>
           <th><input type="submit" value="Submit" name="button" /></th>
           <th><input type="submit" value="Update" name="button" /></th>
           <th><input type="submit" value="Delete" name="button" /></th>
</tr>



So you need to have 3 buttons and the action to be performed by the button with different functions
 
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This cold be one option.  Use some java script that sets the action value in hidden field based on the button click.  Then submit the form using the js code.  On the receiving end retrieve the value of this hidden field to determine what action has been performed.



 
chamini prashakthi
Ranch Hand
Posts: 181
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
M Khalid
Do you mean about use this kind of thing?
<input type="submit" value="Submit" name="button" formaction="path of the relevent redirect jsp  page">
<input type="submit" value="Delete" name="button" formaction="path of the relevent redirect jsp  page">

but it doesn't work for me...
   


 
chamini prashakthi
Ranch Hand
Posts: 181
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Swastik Dey
I need something without javascript.
However thanks for the answer. :thumbup:
 
Swastik Dey
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Take 3 different forms.
 
chamini prashakthi
Ranch Hand
Posts: 181
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How to take different forms in one jsp page?
please explain me!!!
 
Swastik Dey
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
chamini prashakthi
Ranch Hand
Posts: 181
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you mean this kind of thing???
but it dosen't work for me  :cry:

<form  action="Approve/Approve/insertform.jsp method="post" >
           <th><input type="submit" value="Submit" name="button" /></th>
       </form>
       <form  action="Approve/Approve/deleteform.jsp" method="post">
           <th><input type="submit" value="Delete" name="button" /></th>
       </form>
       <form  action="Approve/Approve/modifyform.jsp" method="post">
           <th><input type="submit" value="Update" name="button" /></th>
       </form>

but it doesn't help for me!!!

:confused:
 
Swastik Dey
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does not work means what?  Please be more specific.
 
M Khalid
Ranch Hand
Posts: 100
2
Python Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

chamini prashakthi wrote:Do you mean this kind of thing???
but it dosen't work for me  :cry:

<form  action="Approve/Approve/insertform.jsp method="post" >
           <th><input type="submit" value="Submit" name="button" /></th>
       </form>
       <form  action="Approve/Approve/deleteform.jsp" method="post">
           <th><input type="submit" value="Delete" name="button" /></th>
       </form>
       <form  action="Approve/Approve/modifyform.jsp" method="post">
           <th><input type="submit" value="Update" name="button" /></th>
       </form>

but it doesn't help for me!!!

:confused:



Kindly share the error/logs/error message you are receiving when it doesn't work. The methods mentioned by Swastik are few of the methods which can be implemented and it will work.
What are your exact requirement? and share the whole code snippet if you are facing any issues.
 

 
chamini prashakthi
Ranch Hand
Posts: 181
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this is my main jsp page

<html>

   <head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
       <title>Approver</title>
   </head>
   <body>
       <form  action="Approve/Approve/modifyform.jsp">
       <table>
       <h1>Approval</h1>
     
       <tr>
           <th>Approve ID:</th>
           <th><input type="text" name="Approve_ID" value="" size="20"/></th>
       </tr>
       <tr>
           <th>Notifications:</th>
           <th><input type="text" name="Notofications" value="" size="20"/></th>
       </tr>
       
       <tr>
           <th><input type="submit" value="Submit" name="button" /></th>
           <th><input type="submit" value="Delete" name="button" /></th>
           <th><input type="submit" value="Update" name="button" /></th>
       
       </tr>
       </table>
       
   </body>
</html>

then I want to redirect 3 separate jsp pages for three buttons Submit,Delete and Update.

submit form is-->

<%@page import="calls.ApproveCalls"%>
<%@page import="entity.Approver"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.Map.Entry"%>
<%@page import="java.util.Set"%>
<%@ page import = "java.util.Map" %>
<jsp:useBean id="sample" scope="page" class="calls.ApproveCalls" />

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<%
ApproveCalls approvecalls = new ApproveCalls();    
Approver activity = new Approver(request.getParameter("Approve_ID"),request.getParameter("Notofications"));
activity.setApproverId(activity.getApproverId());
activity.setNotifications(activity.getNotifications());
approvecalls.insertData(activity);
%>


delete form is -->

<%@page import="calls.ApproveCalls"%>
<%@page import="entity.Approver"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.Map.Entry"%>
<%@page import="java.util.Set"%>
<%@ page import = "java.util.Map" %>
<jsp:useBean id="sample" scope="page" class="calls.ApproveCalls" />

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<%
ApproveCalls approvecalls = new ApproveCalls();    
Approver activity = new Approver(request.getParameter("Approve_ID"));
approvecalls.deleteData(activity);

%>


modify form is not finished yet..


I tried previous method and it didn't redirect for next jsp page!  
 
Swastik Dey
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First of all you should never have java code inside jsp page.  Secondly as you said the previous method didn't redirect to jsp page. so what is exactly happening with the previous approach is it leading to any java script issue? Third point , even this page design is not correct.  As per your requirement you should one page with three different forms as I mentioned before.
 
chamini prashakthi
Ranch Hand
Posts: 181
3
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Found a solution

use javascript here



then buttons set like:




:beerchug:
 
Swastik Dey
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Great job.  So how much is difference between my first post and this one?
 
reply
    Bookmark Topic Watch Topic
  • New Topic