I am working on a page where users can choose to email a single file or multiple files. Both options call the same page email.jsp
with their corresponding JavaScript functions.
In the email.jsp page:
String files=null;
String url=null;
String id=null;
String hash=null;
String[] array=null;
String[] split=null;
if(multiemail.equals("no")) {
//get parameters from email()
files= request.getParameter("filename");
url = request.getParameter("link");
id = request.getParameter("id");
hash = request.getParameter("hash");
}else{
split = request.getParameter("link").split(",",0);
array = request.getParameter("arrayList").split(",",0);
}
This logic retrieves four parameters for single emails and two parameters for multiple emails. Next, once these attributes are obtained, I need to pass them to sendemail.jsp
to process the data.
To achieve this, the send button triggers the sendmessage()
function:
$.ajax({
url: 'sendemail.jsp',
type: 'POST',
data: {
recipient: recipient,
subject: subject,
content: content,
id:"<%=id%>",
hash:"<%=hash%>"
},
success: function (data) {
alert("Successfully initiated email to queue");
},
error: function (request, error) {
alert("Request: " + JSON.stringify(error));
}
});
The AJAX call passes data as expected for single emails. However, when sending multiple emails by clicking the same send button, it still includes the unnecessary parameters id
and hash
which are not required based on the email.jsp code logic.
Now, I wonder if there is a way to conditionally pass data based on specific requirements?