日期:2014-05-18  浏览次数:20711 次

在网上找到一个JSP的发送邮件程序,自己稍作修改,但是运行出错,程序很短,达人帮忙看看
<%@   page   import= "java.sql.* "%>  
<%@   page   import= "javax.swing.* "%>  
<%@   page   import= "java.lang.* "%>  
<%@   page   import= "javax.mail.* "%>  
<%@   page   import= "javax.mail.internet.* "%>  
<%@   page   import= "java.util.* "%>  
<%!
String   strToAddr;
String   strSubject;
String   strBody;
String   strFromAddr
%>
<%
public   void   sendMail(strToAddr,   strSubject,   strBody,   strFromAddr)   throws   RemoteException   {%>
<%
try{   %>
<%
Properties   props   =   new   Properties();  
props.put( "mail.smtp.host ", "mail.homenetmail.com ");  
//Here   we   specify   the   SMTP   server   through  
//which   the   mail   should   be   delivered  
Session   session   =   Session.getDefaultInstance(props,   null);  
Message   msg   =   new   MimeMessage(session);  
msg.setFrom(new   InternetAddress(strFromAddr));  
//Specify   the   From   Address  
InternetAddress[]   tos   =InternetAddress.parse(strToAddr);  
//Specify   the   To   Address  
msg.setRecipients(Message.RecipientType.TO,tos);  
msg.setSubject(strSubject);  
//Specify   the   Subject  
msg.setText(strBody);  
//Specify   the   Body  
Transport.send(msg);  
System.out.println( "Message   is   Sent ");  
}  
catch(Exception   e){   %>
<%
System.out.println(e);  
}  
}  
%>
提示出错:  
org.apache.jasper.JasperException:   Unable   to   compile   class   for   JSP


------解决方案--------------------

public void sendMail(strToAddr, strSubject, strBody, strFromAddr) throws RemoteException {%>
<%
try{ %>
<%
去掉
------解决方案--------------------
String strFromAddr是不是差个分号
------解决方案--------------------
1.请楼主先去确定java环境是不是好的,能不能运行java程序。。。
2。尝试去掉throws RemoteException 或者try{}catch(e){}这对。。。
我想差不多就好了
我的异常网推荐解决方案:org.apache.jasper.JasperException: Unable to compile class,http://www.aiyiweb.com/j2ee/2308.html