首页新闻找找看学习计划

The import java.mail cannot be resolved

0
悬赏园豆:20 [已解决问题] 解决于 2017-08-05 10:31

就是一个简易用JSP发送邮件的代码,可是我明明导入包了也CLEAR了还是不对!

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import = "java.io.*,java.util.*" %>
<%@ page import = "javax.mail.internet.*,javax.activation.*" %>
<%@ page import = "javax.servlet.http.*,javax.servlet.*" %>
<%@ page import = "java.mail.*"%>
<%
String result;
String to = "11111@sina.com";
String from = "22222@sina.com";
String host = "loaclhost";
Properties prop= new Properties();
prop.put("mail.smtp.host","smtp.jspinsider.com");
Session sendmailSession;
sendmailSession = Session.getInstance(prop,null);
try{
MimeMessage message = new MimeMessage(sendmailSession);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
message.setSubject("hello world!");
message.setText("你好,世界");
Transport transport;
transport.sendmailSession.getInstance("smtp");
result = "邮件已发送...";
}catch(MessagingException mex)
{
mex.printStackTrace();
result = "ERROR :unable to send message...";
}

%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>send email using JSP</title>
</head>
<body>
<p align="center"> <% out.println("result:"+result +"\n"); %></p>
</body>
</html>

耳朵嫁给了真正的谎的主页 耳朵嫁给了真正的谎 | 初学一级 | 园豆:195
提问于:2017-08-04 17:29
< >
分享
最佳答案
0

改成<%@ page import = "javax.mail.*"%>看看

收获园豆:15
湛泸 | 菜鸟二级 |园豆:239 | 2017-08-04 18:04

改过,没用

耳朵嫁给了真正的谎 | 园豆:195 (初学一级) | 2017-08-04 18:05
其他回答(2)
0

参考

https://stackoverflow.com/questions/12795614/the-import-javax-mail-cannot-be-resolved

ycyzharry | 园豆:20148 (高人七级) | 2017-08-04 18:40

他说的方法我试过了,我添加了呀

0

two jars contains no package java.mail.*, you may remove that import. shu ru fa you wen ti, da bu chu zhong weng, sorry.

收获园豆:5
流年飞雨 | 园豆:1928 (小虾三级) | 2017-08-04 20:17

实现你觉的没错了可还是报错,你可以试一下ctrl+a,然后ctrl+x,然后ctrl+s,然后ctrl+c,然后ctrl+s,剪切,保存,粘贴,保存,因为有可能是IDE透逗了。

支持(0) 反对(0) 流年飞雨 | 园豆:1928 (小虾三级) | 2017-08-04 20:39

@一座城你说你不懂: 你输入法好啦?嗯嗯,我试试,谢谢

清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册