This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JSP and the fly likes Problem with my jsp compilation/Java mail Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Problem with my jsp compilation/Java mail" Watch "Problem with my jsp compilation/Java mail" New topic
Author

Problem with my jsp compilation/Java mail

Bahati
Greenhorn

Joined: Jul 13, 2007
Posts: 1
I have two jsp file:
First one contain form for filling the mail part,called custumers_feedback.jp and the second for executing the first entered information,called mail.jsp
First file:custumers_feedback.jsp,Its code is:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
<!--
.style1 {color: #FF0000}
.style2 {color: #FF0000; font-weight: bold; }
-->
</style>
</head>

<body>
<p> </p>
<p> </p>
<p>  </p>
<p align="right">    <a href="index.jsp">Home</a>   <a href="#" target="_parent"> logIn </a> 
<a href="../../My%20Documents/WebExamples/text_formatting.html">
Customer_feedback</a>   <a href="#">Help</a>   <a href="#">SignUp</a></p>
<table width="1024" border="1">
<tr>
<td width="215"><img src="images/logo.gif" alt="logo" width="215" height="194" longdesc="logo.gif" /></td>
<td width="694" bgcolor="#000000"> <p>  </p>
<p align="center" class="style2">SOFTWARE HUT </p>
<h4 align="center" class="style1">RESOURCES</h4>
<h4 align="center" class="style1">AND </h4>
<h4 align="center" class="style1">PUBLICITY </h4></td>
<td width="234"><img src="images/holcombe.jpg" alt="holcombe" width="215" height="190" /></td>
</tr>
</table>
</a>
<p><font color="#FF0000"><span style="background-color: #FFFFFF">CUSTOMERS FEEDBACK and REQUEST</span></font></p>
<p><span style="background-color: #FFFFFF">To send the request and feedback fill the below form </span></p>
<form name="form1" method="post" action="mail.jsp">
<table width="75" border="0" align="center" cellspacing="1" bgcolor="#006600" class="black">
<tr bgcolor="#FFFFFF">
<td width="24%">sender address:</td>
<td width="76%">
<input name="to" type="text" id="to"></td>
</tr>
<tr bgcolor="#FFFFFF">
<td>title:</td>
<td>
<input name="title" type="text" id="title"></td>
</tr>
<tr>
<td height="107" colspan="2" bgcolor="#FFFFFF">
<textarea name="content" cols="50" rows="5" id="content"></textarea></td>
</tr>
<tr align="center">
<td colspan="2" bgcolor="#FFFFFF">
<input type="submit" name="Submit" value="send">
<input type="reset" name="Submit2" value="reset">
</td>
</tr>
</table>
</form>
 
</body>
</html>

and the second one which executes the entered information is called,mail.jsp:
Its code is:
<%@ page contentType="text/html" %>
<%request.setCharacterEncoding("gb2312");%>

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


<html>
<head>
<meta http-equiv="Content-Type" content="text/html">
<title>send success!</title>
</head>

<body>
<%

try{

//get email information from html
String tto=request.getParameter("to");
String ttitle=request.getParameter("title");
String tcontent=request.getParameter("content");



Properties props=new Properties();//Properties props = System.getProperties();
props.put("mail.smtp.auth","false");
Session s=Session.getInstance(props);//create a new email dialogo according to property
s.setDebug(true);

MimeMessage message=new MimeMessage(s);//create a new message object according email dialogo

//setup email

InternetAddress from=new InternetAddress(tto);
message.setFrom(from);//sender
InternetAddress to=new InternetAddress("acq06dm@sheffield.ac.uk");
message.setRecipient(Message.RecipientType.TO,to);//reciever
message.setSubject(ttitle);//title
message.setText(tcontent);//content
message.setSentDate(new Date());//sending time

//send email
message.saveChanges();//store email information
Transport transport=s.getTransport("smtp");
transport.connect("mailhost.shef.ac.uk","","");//log in the email box
transport.sendMessage(message,message.getAllRecipients());//sending email
transport.close();
%>
<div align="center">
<p><font color="#FF6600">send success!</font></p>
<br>
<a href="mail.jsp">send another</a> </p>
</div>
<%
}
catch(MessagingException e){
out.println(e.toString());
}
%>

</body>
</html>

When I run the first one I got this message:
description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 15 in the jsp file: /mail.jsp
Generated servlet error:
Session cannot be resolved or is not a type

An error occurred at line: 15 in the jsp file: /mail.jsp
Generated servlet error:
Session cannot be resolved

An error occurred at line: 15 in the jsp file: /mail.jsp
Generated servlet error:
MimeMessage cannot be resolved or is not a type

An error occurred at line: 15 in the jsp file: /mail.jsp
Generated servlet error:
MimeMessage cannot be resolved or is not a type

An error occurred at line: 15 in the jsp file: /mail.jsp
Generated servlet error:
InternetAddress cannot be resolved or is not a type

An error occurred at line: 15 in the jsp file: /mail.jsp
Generated servlet error:
InternetAddress cannot be resolved or is not a type

An error occurred at line: 15 in the jsp file: /mail.jsp
Generated servlet error:
InternetAddress cannot be resolved or is not a type

An error occurred at line: 15 in the jsp file: /mail.jsp
Generated servlet error:
InternetAddress cannot be resolved or is not a type

An error occurred at line: 15 in the jsp file: /mail.jsp
Generated servlet error:
Message.RecipientType.TO cannot be resolved or is not a type

An error occurred at line: 15 in the jsp file: /mail.jsp
Generated servlet error:
Transport cannot be resolved or is not a type

An error occurred at line: 55 in the jsp file: /mail.jsp
Generated servlet error:
MessagingException cannot be resolved or is not a type


org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:397)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:288)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:267)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:255)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:556)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:293)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


note The full stack trace of the root cause is available in the Apache Tomcat/5.5.9 logs.

Please tell me what is the problem,I have include two libraries file called mail.jar and activation.jar in the folder called lib WEB-INF.
Please help me for this problem.
Than you.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60741
    
  65

This is an example of just one of the pitfalls of putting processing in a JSP instead of a servlet where it belongs. The variable session is used by JSP as a builtin.

Your first step should be to change the processing ste from a JSP to servlet as best practices dictates.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60741
    
  65

Please check your email for an important message from me.
 
 
subject: Problem with my jsp compilation/Java mail
 
Similar Threads
GET html contents from a web server
Validate() method of ActionForm
Unable to display the Applet in jsp display tomcat
class file is not loading while running JSP file
Error comes whilke compiling the jsp page