• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Creating methods and classes in JSP

santana9

Banned
Hi, I created a mail form that emails a specified individual a set message. Here is the code below:

<%@ page import="java.util.*, javax.mail.*, javax.mail.internet.*" %>
<%

Properties props = new Properties();
props.put("mail.smtp.host", "ncsusraexmea1.na.jnj.com");
Session s = Session.getInstance(props,null);

MimeMessage message = new MimeMessage(s);

String from = request.getParameter("from");
String yourname = request.getParameter("yourname");

String entireFrom = "\"" + yourname + "\" <" + from + ">";

message.setFrom(new InternetAddress(entireFrom));

String toAddresses = request.getParameter("email1");
message.addRecipients(Message.RecipientType.TO, toAddresses);

String ccAddresses = request.getParameter("email2");
message.setRecipients(Message.RecipientType.CC, ccAddresses);

String bccAddresses = request.getParameter("email3");
message.setRecipients(Message.RecipientType.BCC, bccAddresses);

String subject = request.getParameter("subject");
message.setSubject(subject);


String text = request.getParameter("text");
String friendname = request.getParameter("friend1");
String entiretext = "Hello " + friendname + "," + "\n\n" + text;

message.setText(entiretext);

Transport.send(message);
%>

How would I group the various procedures into methods and classes so I can just call a method instead of typing out the same code over. I know you are supposed to invoke the <%! but am unsure how to implement. Thanks in advance.
 
Back
Top