psp程序出错

时间:2014-09-14 16:38:55

标签: jsp javax.mail

我正在使用jsp中的一个项目,我在以下行中遇到错误,这是完整的程序。错误在行

Session session = Session.getInstance(props, auth);

错误是:重复的局部变量“session”。请帮我修复此错误。

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page import = "com.mail.Restaurant.EmailUtil" %>
<%@ page import=java.util.Properties,javax.*,javax.mail.Authenticator,
javax.mail.PasswordAuthentication,javax.mail.Session %>
<!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=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
   final String Message = request.getParameter("Message");
   final String Name = request.getParameter("fname");
   final String Messageowner= ("Hi"+Name+","+"\n\n"+
   "You will be contactedshortly\n    \n\n\n Regards,\n xyz.com");
   final String fromEmail = "abc@gmail.com"; //requires valid gmail id
   final String TID = request.getParameter("email");
   final String password = "password"; // correct password for gmail id
   final String OwnerEmail = "xyz@gmail.com"; // can be any email id 
   final String Ownersubject=("Request from"+Name) ;
   System.out.println("TLSEmail Start");
   Properties props = new Properties();
   props.put("mail.smtp.host", "smtp.gmail.com"); //SMTP Host
   props.put("mail.smtp.port", "587"); //TLS Port
   props.put("mail.smtp.auth", "true"); //enable authentication
   props.put("mail.smtp.starttls.enable", "true"); //enable STARTTLS

           //create Authenticator object to pass in Session.getInstance argument
   Authenticator auth = new Authenticator() {
       //override the getPasswordAuthentication method
       protected PasswordAuthentication getPasswordAuthentication() {
           return new PasswordAuthentication(fromEmail, password);
       }
   };
   Session session = Session.getInstance(props, auth);

   EmailUtil.sendEmail(session, OwnerEmail,"Request from a Person", Message);
   EmailUtil.sendEmail(session, TID,"Restaurant.com", Messageowner);
   %>
   </body>
   </html>

1 个答案:

答案 0 :(得分:1)

Jsp有一组预定义的值,“session”就是其中之一。如果在header标记中设置session =“false”,则jsp-compiler不应包含自己的会话变量声明。