我从JSP2.0书上看到一个例子,应用到Struts项目中,结果出错,希望高手帮我看看错哪了,万分感谢!还有就是书上说javax.activation.*是必须导入的,但是我没看到代码用到啊
----email.jsp------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" pageEncoding="GB2312"%>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/core" prefix="c"%><html xmlns="http://www.w3.org/1999/xhtml" lang="gb2312">
<head>
<html:base />
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<meta http-equiv="Content-Language" content="gb2312" />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
</head>
<body>
<%--页面头部--%>
<jsp:include page="/pages/include/header.jsp" flush="" />
<%--页面左部--%>
<jsp:include page="left.jsp" flush="" />
<%--页面中部--%>
<div id="content2">
<html:errors />
<div class="mtitle">邮件催还</div>
<div class="mcontent">
<html:form action="/magbookmanage/SendMail">
<table width="75%">
tbody>
<tr><th width="20%">寄信人</th><td width="80%"><html:text property="send" value="${id}" size="50"/></td></tr>
<tr><th width="20%">收信人</th><td width="45%"><html:text property="receive" value="${name}" size="50"/></td></tr>
<tr><th width="20%">主 题</th><td width="80%"><html:text property="subject" size="60"/></td></tr> <tr><th width="20%">内 容</th><td><html:textarea property="content" /></td></tr>
</tbody>
<tfoot>
<tr><td colspan="4"><html:submit>发送</html:submit> <html:cancel>取消</html:cancel></td> </tr>
</tfoot>
</table>
</html:form>
</div>
</div>
<%--页面底部--%>
<jsp:include page="/pages/include/foot.jsp" flush="" />
</body>
</html>
---SendMailAction----package xkjs.action.magbookmanage;import java.util.Date;
import java.util.Properties;import javax.activation.*;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import org.apache.commons.beanutils.PropertyUtils;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;import xkjs.bean.magbookmanage.MailBean;
import xkjs.form.magbookmanage.MailForm;public class SendMailAction extends Action { public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws Exception {
MailForm mailForm = (MailForm) form;
MailBean mail = new MailBean();
InternetAddress[] address = null;
request.setCharacterEncoding("GB2312");
boolean sessionDebug = false;
String mailServer = "www.126.com";//////
PropertyUtils.copyProperties(mail,mailForm);
try{
Properties properties=System.getProperties();
properties.put("mail.host",mailServer);
properties.put("mail.transport.protocol","smtp");
Session mailSession=Session.getDefaultInstance(properties,null);
mailSession.setDebug(sessionDebug);
Message message=new MimeMessage(mailSession);
message.setFrom(new InternetAddress(mail.getSend()));
address=InternetAddress.parse(mail.getReceive(),false);
message.addRecipients(Message.RecipientType.TO,address);
message.setSubject(mail.getSubject());
message.setSentDate(new Date());
message.setText(mail.getContent());
Transport.send(message);
request.setAttribute("result","成功发送!");
}catch(MessagingException mex){
mex.printStackTrace();
request.setAttribute("result","发送失败!");
}
return mapping.findForward( "result");
}
}---MailForm.java----package xkjs.form.magbookmanage;import javax.servlet.http.HttpServletRequest;import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;public class MailForm extends ActionForm { private String send;
private String action;
private String receive;
private String subject;
private String content; public ActionErrors validate(
ActionMapping mapping,
HttpServletRequest request) { // TODO Auto-generated method stub
return null;
}
public void reset(ActionMapping mapping, HttpServletRequest request) { // TODO Auto-generated method stub
}
public String getSend() {
return send;
}
public void setSend(String send) {
this.send = send;
}
public String getAction() {
return action;
}
public void setAction(String action) {
this.action = action;
}
public String getReceive() {
return receive;
}
public void setReceive(String receive) {
this.receive = receive;
}
public String getSubject() {
return subject;
}
public void setSubject(String subject) {
this.subject = subject;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
}
----email.jsp------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" pageEncoding="GB2312"%>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/core" prefix="c"%><html xmlns="http://www.w3.org/1999/xhtml" lang="gb2312">
<head>
<html:base />
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<meta http-equiv="Content-Language" content="gb2312" />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
</head>
<body>
<%--页面头部--%>
<jsp:include page="/pages/include/header.jsp" flush="" />
<%--页面左部--%>
<jsp:include page="left.jsp" flush="" />
<%--页面中部--%>
<div id="content2">
<html:errors />
<div class="mtitle">邮件催还</div>
<div class="mcontent">
<html:form action="/magbookmanage/SendMail">
<table width="75%">
tbody>
<tr><th width="20%">寄信人</th><td width="80%"><html:text property="send" value="${id}" size="50"/></td></tr>
<tr><th width="20%">收信人</th><td width="45%"><html:text property="receive" value="${name}" size="50"/></td></tr>
<tr><th width="20%">主 题</th><td width="80%"><html:text property="subject" size="60"/></td></tr> <tr><th width="20%">内 容</th><td><html:textarea property="content" /></td></tr>
</tbody>
<tfoot>
<tr><td colspan="4"><html:submit>发送</html:submit> <html:cancel>取消</html:cancel></td> </tr>
</tfoot>
</table>
</html:form>
</div>
</div>
<%--页面底部--%>
<jsp:include page="/pages/include/foot.jsp" flush="" />
</body>
</html>
---SendMailAction----package xkjs.action.magbookmanage;import java.util.Date;
import java.util.Properties;import javax.activation.*;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import org.apache.commons.beanutils.PropertyUtils;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;import xkjs.bean.magbookmanage.MailBean;
import xkjs.form.magbookmanage.MailForm;public class SendMailAction extends Action { public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws Exception {
MailForm mailForm = (MailForm) form;
MailBean mail = new MailBean();
InternetAddress[] address = null;
request.setCharacterEncoding("GB2312");
boolean sessionDebug = false;
String mailServer = "www.126.com";//////
PropertyUtils.copyProperties(mail,mailForm);
try{
Properties properties=System.getProperties();
properties.put("mail.host",mailServer);
properties.put("mail.transport.protocol","smtp");
Session mailSession=Session.getDefaultInstance(properties,null);
mailSession.setDebug(sessionDebug);
Message message=new MimeMessage(mailSession);
message.setFrom(new InternetAddress(mail.getSend()));
address=InternetAddress.parse(mail.getReceive(),false);
message.addRecipients(Message.RecipientType.TO,address);
message.setSubject(mail.getSubject());
message.setSentDate(new Date());
message.setText(mail.getContent());
Transport.send(message);
request.setAttribute("result","成功发送!");
}catch(MessagingException mex){
mex.printStackTrace();
request.setAttribute("result","发送失败!");
}
return mapping.findForward( "result");
}
}---MailForm.java----package xkjs.form.magbookmanage;import javax.servlet.http.HttpServletRequest;import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;public class MailForm extends ActionForm { private String send;
private String action;
private String receive;
private String subject;
private String content; public ActionErrors validate(
ActionMapping mapping,
HttpServletRequest request) { // TODO Auto-generated method stub
return null;
}
public void reset(ActionMapping mapping, HttpServletRequest request) { // TODO Auto-generated method stub
}
public String getSend() {
return send;
}
public void setSend(String send) {
this.send = send;
}
public String getAction() {
return action;
}
public void setAction(String action) {
this.action = action;
}
public String getReceive() {
return receive;
}
public void setReceive(String receive) {
this.receive = receive;
}
public String getSubject() {
return subject;
}
public void setSubject(String subject) {
this.subject = subject;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
}
解决方案 »
- 一个function的问题
- 在ECLIPSE下,用封装好的JAVABEAN无法利用桥接器获得ACCESS数据。。。。
- 有哪位大哥告诉小妹怎么在同一页面重复使用滑动门效果?急急急!!!!!
- 获得hashtable的key
- 求助!!jsp连数据库的一个小问题!
- 大家来帮忙~~为什么在JPanel绘图不能显示出来呢~??
- 一个Javascript的问题
- 200分求解决方案!!!
- 大家请进来!!java论坛(主要做OA),请大家提意见
- ssh架构,sevice层继承dao层 这种结构合理吗?
- 不用Sql语句,用循环语句,可以去掉重复记录吗?
- [高分求救]主页采用用转址技术后session出现跨域问题.请各位帮忙.比较急!
Servlet.service() for servlet action threw exception
java.lang.NoClassDefFoundError: javax/activation/DataSource
at xkjs.action.magbookmanage.SendMailAction.execute(SendMailAction.java:68)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at xkjs.utils.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:57)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)