java - Moving to different servlet other than form action -
i having form :
<form action="sendaddnotification" method="post"> <%string namee=rs.getstring(2);%> <input name="indusername" type="hidden" value="<%=namee%>"/> user name : <%=namee%> <br> first name : <%=rs.getstring(4)%> <br> last name : <%=rs.getstring(5)%> <br> email id : <%=rs.getstring(6)%> <br> contact : <%=rs.getstring(7)%> <br> <% string groupidd = request.getsession().getattribute("groupid").tostring(); s=null; rs=null; int flag=0; string sql="select * tbgroupusers i_id=? , gu_groupid=?"; s = con.preparestatement(sql); s.setstring(1,idperson); s.setstring(2,groupidd); rs=s.executequery(); if(rs.next()) flag=1; request.setattribute("flag", flag); %> <c:choose> <c:when test="${requestscope.flag == 1}"> <!-- flag 1 --> <input type="submit" value="request sent" disabled="disabled"></input> <a href="cancelrequest?userid=<%=idperson%>&userrnamee=<%=namee%>" onclick="return confirm('are sure want cancel request?');"> <input type="submit" value="cancel request"></input> </a> </c:when> <c:otherwise> <!-- flag isn't 1 --> <input type="submit" value="add"></input> </c:otherwise> </c:choose> <a href="searchdatabasetoadd.jsp"><input type="button" value="back"></input></a> </form>
now ,in part of code :
<a href="cancelrequest?userid=<%=idperson%>&userrnamee=<%=namee%>" onclick="return confirm('are sure want cancel request?');"> <input type="submit" value="cancel request"></input> </a>
i want move servlet cancelrequest.java given parameters.but form action goes sendaddnotification,so servlet never runs.
how make run on click of button.please help
assuming cancelrequest servlet defined in web.xml as:
<servlet> <servlet-name>cancelrequest</servlet-name> <servlet-path>packagename.cancelrequest</servlet-path> </servlet> <servlet-mapping> <servlet-name>cancelrequest</servlet-name> <url-pattern>/cancelrequest</url-pattern> </servlet-mapping>
write javascript function as:
function cancelrequest(){ var exit = confirm('are sure want cancel request?'); if(exit == true){ document.getelementbyid('sendaddnotificationid').action = 'cancelrequest'; }else{ return; } }
include id form in jsp as:
<form action="sendaddnotification" id="sendaddnotificationid" method="post">
and change anchor element as:
<a href="cancelrequest?userid=<%=idperson%>&userrnamee=<%=namee%>" onclick="cancelrequest();"> <input type="submit" value="cancel request"></input> </a>
Comments
Post a Comment