java - Why am I getting "Duplicate local variable error" here? -
i have code trying send email using java mail api. when running code in eclipse, getting error "multiple annotations found @ line:duplicate local variable session". have declared session variable once why getting error?
try{ string host="smtp.gmail.com"; string to="abc@gmail.com"; final string user="xyz@gmail.com"; final string password="*********"; properties properties = system.getproperties(); properties.setproperty("mail.smtp.host",host ); properties.put("mail.smtp.auth", "true"); session session = session.getdefaultinstance(properties, new javax.mail.authenticator() { protected passwordauthentication getpasswordauthentication() { return new passwordauthentication(user,password); } }); mimemessage message = new mimemessage(session); message.setfrom(new internetaddress(user)); message.addrecipient(message.recipienttype.to, new internetaddress(to)); message.setsubject("thank subscriber"); message.setcontent("<table><tr><td>name</td><td>+name+</td></tr><tr><td>address</td><td>+addr+</td></tr><tr><td>age</td><td>+age+</td></tr><tr><td>qualification</td><td>+qual+</td></tr><tr><td>percentage</td><td>+persent+</td></tr><tr><td>passout</td><td>+year+</td></tr></table>","text/html"); transport.send(message); system.out.println("message sent...."); } catch (messagingexception ex) {ex.printstacktrace();} {}
this servlet using.
package com.registration; import java.io.ioexception; import java.io.printwriter; import javax.servlet.requestdispatcher; import javax.servlet.servletexception; import javax.servlet.http.httpservlet; import javax.servlet.http.httpservletrequest; import javax.servlet.http.httpservletresponse; /** * servlet implementation class registrationcontroller */ public class registrationcontroller extends httpservlet { private static final long serialversionuid = 1l; /** * @see httpservlet#httpservlet() */ public registrationcontroller() { super(); // todo auto-generated constructor stub } /** * @see httpservlet#doget(httpservletrequest request, httpservletresponse response) */ protected void doget(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception { // todo auto-generated method stub } /** * @see httpservlet#dopost(httpservletrequest request, httpservletresponse response) */ protected void dopost(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception { // todo auto-generated method stub response.setcontenttype("text/html"); printwriter out = response.getwriter(); string name = request.getparameter("fullname"); string addr = request.getparameter("address"); string age = request.getparameter("age"); string qual = request.getparameter("qual"); string persent = request.getparameter("percent"); string year = request.getparameter("yop"); if(name.isempty()||addr.isempty()||age.isempty()||qual.isempty()||persent.isempty()||year.isempty()) { requestdispatcher rd = request.getrequestdispatcher("registration.jsp"); out.println("<font color=red>oops!! missed out fields. fill them again</font>"); rd.include(request, response); } else { requestdispatcher rd = request.getrequestdispatcher("home.jsp"); rd.forward(request, response); } } }
jsp has inbuilt session variable can use. since reusing getting duplicate error.
this equivalent of doing session session=request.getsession() in servlet;
Comments
Post a Comment