1.javaMail
//******** SendmailServlet *********//
package javamvc;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.mail.internet.AddressException;
import javax.activation.*;
import java.util.Properties;
public class SendmailServlet extends HttpServlet
{
private static final String CONTENT_TYPE = "text/html; charset= GB2312";
public void init() throws ServletException
{
}
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException,
IOException
{
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
HttpSession session1=request.getSession();
if(session1.getAttribute("controller")!=null&&session1.getAttribute("purview")!=null)
{
String from = request.getParameter("txtfrom"); //获取发件人的邮箱地址
String to = request.getParameter("txtto"); //获取收件人的邮箱地址
String subject = request.getParameter("txtsubject"); //获取邮件的主题
String body = request.getParameter("txtmessage"); //获取邮件的内容
String fileAttachment = request.getParameter("txtattachment"); //获取附件文件的硬盘地址
System.out.println("发件人:"+from+" 收件人:"+to+" 主题:"+subject+" 内容:"+body+" 附件:"+fileAttachment);
if(from!=null&&to!=null&&subject!=null&&body!=null&&fileAttachment!=null)
{
try {
Properties props = System.getProperties(); //设置相关的配置信息
props.put("mail.smtp.host", "smtp.126.com"); //设置发送邮件所使用的协议,smtp是发送邮件的协议,smtp.126.com是邮件服务器名称
//设置发送邮件所使用的协议
//props.put("mail.transport.protocol","smtp");
//设置发送邮件协议的端口号
//props.put("mail.smtp.port","25");
//设置发送邮件所需的认证信息:用户名,密码
props.put("mail.smtp.auth","true");
MyAuth auth = new MyAuth("accps2135","xy21352135");
//创建发送时的会话
Session session = Session.getInstance(props, null);
MimeMessage message = new MimeMessage(session); //创建发送邮件所需的会话
message.setFrom(new InternetAddress(from)); //设置发件人
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(to)); //设置收件人
message.setSubject(subject); //设置邮件的主题
MimeBodyPart messageBodyPart = new MimeBodyPart(); //创建一个空的内容对象,可放邮件的主题内容body
messageBodyPart.setText(body); //将邮件的内容放入内容对象messageBodyPart中
Multipart multipart = new MimeMultipart(); //创建最终的内容主体对象multipart
multipart.addBodyPart(messageBodyPart); //将装有从页面中传过来的内容的内容对象messageBodyPart放入最终的内容主体对象multipart中
messageBodyPart = new MimeBodyPart(); //重新创建一个空的内容MimeBodyPart对象,可放附件
//*******将本地硬盘的文件转换为mail的附件********//
DataSource source = new FileDataSource(fileAttachment); //创建数据源对象
messageBodyPart.setDataHandler(new DataHandler(source)); //设置附件内容的处理
messageBodyPart.setFileName(fileAttachment); //设置附件内容的文件名
//
multipart.addBodyPart(messageBodyPart); //将装有附件内容的内容对象messageBodyPart放入最终的内容主体对象multipart中
message.setContent(multipart); //最后将最终的内容主体对象multipart放入邮件对话的主体内容中
///////////////Transport.send(message); //最最终发送邮件(产生异常了!!)
if(session1.getAttribute("mailid")!=null&&session1.getAttribute("pagenum")!=null)
{
String mailid=session1.getAttribute("mailid").toString();//获取发送邮件的id
String pagenum=session1.getAttribute("pagenum").toString();//获取页面数
String sql="update 申请表 set 回复状态='此申请已经回复' where 申请Id="+mailid;
DataSql data=new DataSql();
int i=data.getUptateResult(sql);
String sendmailstate="yes";
request.setAttribute("sendmailstate",sendmailstate);//将发送邮件的状态放入request
request.getRequestDispatcher("backleagueservlet?pagenum="+pagenum).forward(request,response);//跳到后台申请管理页面
}
else
{
System.out.print("发送邮件Servlet产生错误,没能传过来邮件的Id");
response.sendRedirect("front/error.jsp");//跳转到错误页面
}
}
catch (Exception e) {
out.println(e);
}
}
else
{
System.out.print("没有从上个页面中传来邮件的值!!");
response.sendRedirect("front/error.jsp");//跳转到错误页面
}
}else
{
response.sendRedirect("background/controllerEnter.jsp");//返回管理员登录页面登录
}
}
//Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
doGet(request, response);
}
public void destroy()
{
}
}
2.异步提交
//******** shop.jsp *********//
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="GBK"%>★★
<script>
//创建xml异步提交的对象
function asynchronismsub()
{
//创建xmlHttp对象,固定写法
if(window.ActiveXObject)//微软IE浏览器
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");//创建微软IE浏览器的异步提交对象
}
else if(window.XMLHttpRequest)//非微软IE浏览器
{
xmlHttp = new XMLHttpRequest();//创建非微软IE浏览器的异步提交对象
}
//设置处理响应的函数
xmlHttp.onreadystatechange = myfunc;//设置相应的响应函数的名称叫myfunc
//设置请求的服务端
var shopname=document.getElementById("shopname").value;//获取店名的文本中的值
var shopaddress=document.getElementById("shopaddress").value;//获取店址的文本中的值
var endyear=document.getElementById("endyear").value;//获取年的文本中的值
var endmonth=document.getElementById("endmonth").value;//获取月的文本中的值
var endday=document.getElementById("endday").value;//获取日的文本中的值
var shoptext=document.getElementById("shoptext").value;//获取简介的文本中的值
xmlHttp.open("POST","backaddshopasynchronismservlet",true);//设置异步提交的方式为:POST,提交到servlet,
//true为是一个异步提交,false为不是异步提交
xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
//固定写法
//使用post方式提交时需要设置Content_Type头,使用get方式则不需要
xmlHttp.send("shopname="+encodeURI(shopname)+"&shopaddress="+encodeURI(shopaddress)+"&endyear="+encodeURI(endyear)+"&endmonth="+encodeURI(endmonth)+"&endday="+encodeURI(endday)+"&shoptext="+encodeURI(shoptext));//将姓名的文本中的值传给servlet★★
//encodeURI中文处理
//使用破碎post方式提交,传递参数时使用url重写的方式,使用get方式则不需要
}
//响应的结果
function myfu
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
①主要功能模块: 开发此系统的需求源于:加盟店对自身品牌宣传,达到品牌效应,吸引更多的客源。 该系统是一个包含前台的基础数据展示,用户的加盟申请,后台的数据管理与查询 ■前台: 1.留言版(用户可对本网站进行留言或咨询) 2.BBS论坛 3.加盟申请 ■后台: 1.信息更新 2.审核加盟申请 3.内部人员的管理 4.留言版的回复 ②技术特点: 该系统用的是C/S架构,MVC三层设计模式 , 里面用到的技能点有,JavaBean,Jsp/Servlet,JDBC,javaMail实现邮件发送, Ajax实现异步提交,用SmartUpload组件上传 图片。 注意:只能用于学习,不可做其他用途
资源推荐
资源详情
资源评论
收起资源包目录
咖啡店加盟网站 (JBuilder2005 + SQL Service 2000) (2000个子文件)
QQ截图未命名.bmp 114KB
league_jsp.class 51KB
topic_jsp.class 49KB
shop_jsp.class 49KB
leaveword_jsp.class 46KB
league_jsp.class 46KB
examineLeaveword_jsp.class 45KB
newshop_jsp.class 44KB
shop_jsp.class 43KB
newcoffee_jsp.class 43KB
leaveword_jsp.class 42KB
examineLeaveword_jsp.class 41KB
selectdaytopic_jsp.class 41KB
selectdaytopic_jsp.class 38KB
newcoffee_jsp.class 38KB
coffee_jsp.class 35KB
newshop_jsp.class 35KB
coffee_jsp.class 35KB
coffeeProduct_jsp.class 28KB
forum_jsp.class 27KB
forum_jsp.class 26KB
bbsTopicTitle_jsp.class 26KB
shopProduct_jsp.class 26KB
writeLeaveword_jsp.class 25KB
bbsSction_jsp.class 23KB
coffeeProduct_jsp.class 23KB
user_jsp.class 23KB
contollerfirst_jsp.class 23KB
user_jsp.class 23KB
contollerfirst_jsp.class 22KB
shopProduct_jsp.class 22KB
mail_jsp.class 21KB
mail_jsp.class 21KB
selectcoffee_jsp.class 21KB
selectcoffee_jsp.class 21KB
bbsTopicTitle_jsp.class 21KB
writeLeaveword_jsp.class 21KB
updateshoppage_jsp.class 21KB
updateshoppage_jsp.class 20KB
bbsSction_jsp.class 19KB
addtopic_jsp.class 15KB
login_jsp.class 15KB
topicpreview_jsp.class 14KB
bbsTopicContent_jsp.class 14KB
controllerEnter_jsp.class 13KB
addtopic_jsp.class 12KB
login_jsp.class 12KB
topicpreview_jsp.class 11KB
controllerEnter_jsp.class 11KB
bbsTopicContent_jsp.class 11KB
loginState_jsp.class 10KB
forumEnterError_jsp.class 10KB
loginState_jsp.class 8KB
BackSelectTimeTopicServlet.class 8KB
BackSelectTimeTopicServlet.class 8KB
forumEnterError_jsp.class 8KB
BbsSctionServlet.class 8KB
BbsSctionServlet.class 8KB
BackSelectLeagueServlet.class 7KB
BackSelectLeagueServlet.class 7KB
applystate_jsp.class 7KB
Leavewordstate_jsp.class 7KB
addtopicstate_jsp.class 7KB
TodayAndYesterdayTopicServlet.class 7KB
TodayAndYesterdayTopicServlet.class 7KB
BackSelectLeaveWordServlet.class 7KB
BackSelectLeaveWordServlet.class 7KB
BackTopicServlet.class 7KB
BackTopicServlet.class 7KB
error_jsp.class 7KB
applystate_jsp.class 6KB
Leavewordstate_jsp.class 6KB
addtopicstate_jsp.class 6KB
TopicTitleServlet.class 6KB
TopicTitleServlet.class 6KB
BackLeagueServlet.class 6KB
BackLeagueServlet.class 6KB
TodayLeagueServlet.class 6KB
TodayLeagueServlet.class 6KB
error_jsp.class 6KB
BackForumServlet.class 6KB
BackForumServlet.class 6KB
BackLeaveWordServlet.class 6KB
BackLeaveWordServlet.class 6KB
TodayLeaveWordServlet.class 5KB
TodayLeaveWordServlet.class 5KB
SendmailServlet.class 5KB
SendmailServlet.class 5KB
LeagueBean.class 5KB
LeagueBean.class 5KB
BackCoffeeAndNewcoffeeServlet.class 5KB
BackCoffeeAndNewcoffeeServlet.class 5KB
BackShopServlet.class 5KB
BackShopServlet.class 5KB
TopicContentServlet.class 5KB
TopicContentServlet.class 5KB
CoffeeServlet.class 5KB
CoffeeServlet.class 5KB
BackaddCoffeeServlet.class 4KB
BackaddCoffeeServlet.class 4KB
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
wszlh1981
- 粉丝: 13
- 资源: 15
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功