Note that there are some explanatory texts on larger screens.

plurals
  1. POAJAX - JSP not executed on POST
    primarykey
    data
    text
    <p>I need to send a mail with jsp, but the page itself mustn't reload. The whole implementation is working fine when reloading on the POST-event, but adjusting the code to work with ajax breaks it. It seems that the jsp-Code within the index.jsp is not executed, when the ajax event is triggerd. I am gonna show some snippets: </p> <p>index.jsp</p> <pre><code> &lt;% String result = "=("; String to = request.getParameter("rec_mail"); if(to != null) { String from = request.getParameter("sendermail"); String host = "mailserver"; Properties properties = System.getProperties(); properties.setProperty("mail.smtp.host", host); Session mailSession = Session.getDefaultInstance(properties); try{ MimeMessage message = new MimeMessage(mailSession); message.setFrom(new InternetAddress(from)); message.addRecipient(Message.RecipientType.TO, new InternetAddress(to)); message.setSubject("Feedback"); message.setText(request.getParameter("feedbackinput")); Transport.send(message); result = "Sucess!"; }catch (MessagingException e) { e.printStackTrace(); result = "failed!"; } } out.println(request.getParameter("sendermail")); out.println(result); %&gt; &lt;input id="bsend" class="fbutton" type="submit" name="send" value="Send" onclick="loadContent()" style="float:right; width:18%; height:35%;" &gt; </code></pre> <p>ajax.js</p> <pre><code>var xmlhttp function loadContent() { xmlhttp=GetXmlHttpObject(); if (xmlhttp==null) { alert ("Your browser does not support Ajax!"); return; } var url="./index.jsp"; xmlhttp.open("post",url,true); xmlhttp.send(null); xmlhttp.onreadystatechange=getOutput; } function getOutput() { if (xmlhttp.readyState==4) { alert("Message sent!"); } } function GetXmlHttpObject() { if (window.XMLHttpRequest) { return new XMLHttpRequest(); } if (window.ActiveXObject) { return new ActiveXObject("Microsoft.XMLHTTP"); } return null; } </code></pre> <p>(just showing the relevant parts, everywhere)</p> <p>I get the alert-message, but no mail is sent ... I hope it is clear, what I am trying to do..</p> <p>Thank you!</p> <p>Best regards</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload