?
Solved

variable problem...

Posted on 2003-03-31
8
Medium Priority
?
171 Views
Last Modified: 2010-04-01
This is my error:
http:\\www.iprofilecentral.com\default.asp?cid=46922&UID=140786&CHECK=d9c623bc0600318e19e9381e57f6a7ed

This is my code:

This variable is declared higher up page:
String vEmail = (String) session.getAttribute("Email");

Then after this code is used to send an email but vEmail isn't recognised.  Why??

           //send email to customer
        String from="pictures@mydesres.com";
        String to="+vEmail+";
        //out.println(to);
        try{
            SmtpClient client = new SmtpClient("mail.xxxxx.xxx");
            client.from(from);
            //client.to(to);
            client.to(vEmail);
            PrintStream message = client.startMessage();
            message.println("To: " + to);
            message.println("Subject:  ");
            message.println();
            message.println();
            message.println("Your reference ID is:"+ PropertyIDVal);
            message.println();    
            message.println();
            client.closeServer();
         }
         catch (IOException e){    
            System.out.println("ERROR SENDING EMAIL:"+e);
         }
        %>
         
0
Comment
Question by:jhazard
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 11

Expert Comment

by:fargo
ID: 8237702
Hii,

In your code...

  String to="+vEmail+"; is not required..u can replace the above with   String to=vEmail;

As vEmail is a string type only, there is no need to put "".

Hope this helps
thanks and regards
happy working
fargo

0
 
LVL 11

Expert Comment

by:fargo
ID: 8237724
Hii,

just thinking...try this also

String vEmail = session.getAttribute("Email").toString();

thanks
0
 

Author Comment

by:jhazard
ID: 8237733
I tried that before and it now gives me this error...

Error: 500
Location: /final.jsp
Internal Servlet Error:

org.apache.jasper.JasperException: Unable to compile class for JSPNote: sun.tools.javac.Main has been deprecated.
/usr/local/tomcat3/work/www.mydesres.com_8080/_0002ffinal_0002ejspfinal_jsp_0.java:174: Undefined variable: vEmail
                        String to=vEmail;
                                  ^
/usr/local/tomcat3/work/www.mydesres.com_8080/_0002ffinal_0002ejspfinal_jsp_0.java:180: Undefined variable: vEmail
                            client.to(vEmail);
                                      ^
2 errors, 1 warning


0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 11

Expert Comment

by:fargo
ID: 8237754
Hii,

Could you post where have u defined vEmail in ur page...if u provide the code, then someone can help u better.

There is a problem with vEmail variable declaration...u might have declared it inside a try catch loop..as a local variable..try to make it global (this is my guess..w/o seeing ur code)

fargo
0
 

Author Comment

by:jhazard
ID: 8237850
This is all of my code:
<html>
<head>
<%@ include file="headerandbuttons.jsp" %>
<%@ page language="java" import="java.util.*, java.sql.*" %>
<%@ page import="sun.net.smtp.SmtpClient, java.io.*" %>
<jsp:useBean id="db1" scope="page" class="com.desres.db.CreateConnection" />
</head>
<body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" background="images/tile_top.gif" onLoad="MM_preloadImages('images/buy_hi.gif','images/sell_hi.gif','images/links_hi.gif','images/aboutus_hi.gif','images/contactus_hi.gif')">
<%
String action="";
String insertString="";
String insertString2="";
String insertString3="";
int PropertyIDVal = 0;

action=request.getParameter("action");

if (action.equals("confirm"))
{
      String vCountry = (String) session.getAttribute("Country");
      String vCounty = (String) session.getAttribute("County");
      String vTown = (String) session.getAttribute("Town");
      String vPostCode = (String) session.getAttribute("PostCode");
      String vType = (String) session.getAttribute("Type");
      String vBedrooms = (String) session.getAttribute("Bedrooms");
      String vGarden = (String) session.getAttribute("Garden");
      String vGarage = (String) session.getAttribute("Garage");
      String vPrice = (String) session.getAttribute("Price");
      String vStation = (String) session.getAttribute("Station");
      
      String vContactName = (String) session.getAttribute("ContactName");
      String vEmail = (String) session.getAttribute("Email");
      String vDaytime = (String) session.getAttribute("Daytime");
      String vEvening = (String) session.getAttribute("Evening");
      String vMobile = (String) session.getAttribute("Mobile");
      
      String vTitle = (String) session.getAttribute("Title");
      String vFirstName = (String) session.getAttribute("FirstName");
      String vSurname = (String) session.getAttribute("Surname");
      String vHouseNo = (String) session.getAttribute("House");
      String vPostcode2 = (String) session.getAttribute("Postcode2");
      String vUserName = (String) session.getAttribute("UserName");
      String vPassword = (String) session.getAttribute("Password");


      Connection newConn = db1.CreateConnection();
      java.sql.Statement myStmt = newConn.createStatement();

      insertString = "INSERT INTO tblProperty(PropertyID,Country,County,Town,PostCode,Type,Bedrooms,Garden,Garage,Price,Paid,Status,TandC,DateAdded,Station) VALUES(last_insert_id(),ucase('"+vCountry+"'),ucase('"+vCounty+"'),ucase('"+vTown+"'),ucase('"+vPostCode+"'),'"+vType+"','"+vBedrooms+"','"+vGarden+"','"+vGarage+"','"+vPrice+"','NO','NO','YES',SYSDATE(),'"+vStation+"')";
      //out.println(insertString);
      myStmt.execute(insertString);
                  
      ResultSet myRs = myStmt.executeQuery("SELECT max(PropertyID) PropertyIDVal FROM tblProperty");
        while(myRs.next())
        {
        PropertyIDVal = myRs.getInt("PropertyIDVal");
      }

      insertString2 = "INSERT INTO tblContact(ContactID,PropertyID,ContactName,Email,Mobile,Daytime,Evening) VALUES(last_insert_id(),'"+PropertyIDVal+"','"+vContactName+"','"+vEmail+"','"+vMobile+"','"+vDaytime+"','"+vEvening+"')";
      myStmt.execute(insertString2);
      
      insertString3 = "INSERT INTO tblCustomer(CustomerID,PropertyID,Title,FirstName,Surname,Username,Password,HouseNo,Postcode) VALUES(last_insert_id(),'"+PropertyIDVal+"','"+vTitle+"','"+vFirstName+"','"+vSurname+"','"+vUserName+"','"+vPassword+"','"+vHouseNo+"','"+vPostcode2+"')";
      myStmt.execute(insertString3);
      
             myStmt.close();               
             
}  
%>


<table width="662" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="170" height="49" valign="top"><img src="images/logo_desres.gif" width="170" height="65" usemap="#Map" border="0"></td>
        <td colspan="2" valign="top" height="49"><img src="images/pixel.gif" width="590" height="27"><br>
        <img src="images/pixel.gif" width="20" height="17"><img src="images/h_sell.gif" width="274" height="17"><br>
    <img src="images/pixel.gif" width="590" height="21"></td>

  </tr>
  <tr>
    <%@ include file="buttons.jsp" %>
    <td width="496" bgcolor="#FFFFFF" valign="top">
      <table width="446" border="0" cellspacing="0" cellpadding="20">
        <tr>
        <br>
          <td valign="top" class="txt_bold">
                  <p>Thank you for using desres.com </p>
              </td></tr>
              <tr>
          <td valign="top" class="txt">
         
          <%
           //send email to customer!!!
         String from="pictures@desres.com";
         String to=vEmail;
         //out.println(to);
         try{
             SmtpClient client = new SmtpClient("mail.xxxxx.xxx");
             client.from(from);
             //client.to(to);
             client.to(vEmail);
             PrintStream message = client.startMessage();
             message.println("To: " + to);
             message.println("");
             message.println("");
             message.println();
             message.println("Your reference ID is:"+ PropertyIDVal);
             message.println();    
             message.println();
             client.closeServer();
          }
          catch (IOException e){      
             System.out.println("ERROR SENDING EMAIL:"+e);
          }
         %>
         
         
         
          <p>Your ref. id is: <%=PropertyIDVal%></p>
          <p> It has also been emailed to you, please keep this <br>
            safe as you will need it if you want to change or  <br>
            delete your advert. </p>
          <p>Email your pictures to <a href="mailto:pictures@desres.com">pictures@desres.com</a>,<br>
          quoting your reference in the subject line.  </p>
          <p>On receipt of these your advert will appear within <br>
          24 hours.</p>
       
        </td>
        </tr>
        <tr>
          <td><img src="images/pixel.gif" width="406" height="20"></td>
        </tr>
      </table>
    </td>
    <td width="135" bgcolor="#FFFFFF" valign="top"><br>
      <img src="images/image_window.gif" width="144" height="333"></td>
  </tr>
</table>
<map name="Map">
  <area shape="rect" coords="7,2,170,60" href="index.jsp">
</map>
</body>
</html>
0
 
LVL 11

Accepted Solution

by:
fargo earned 80 total points
ID: 8237859
Hii,

Take the declaration of vEmail out of if(action.equals("confirm ")) loop...and declared as others like action and insertString declaration..

String vEmail = "";

I suppose, then u will get the email...

Hope this works
fargo
0
 

Author Comment

by:jhazard
ID: 8238082
Thats worked although I'm still confused as to why it didn't before as the argument passed was confirm.
Thanks for your help anyway.
0
 
LVL 11

Expert Comment

by:fargo
ID: 8238146
Hii jhazard,

It is always better to declare and initialize a variable globally and then assign the values. (if you would like to use the variable in all document).
Well, it's good that it worked up.

thanks for the points
happy working
fargo
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introducing Priority Question, our latest feature.
In today's business world, data is more important than ever for informing marketing campaigns. Accessing and using data, however, may not come naturally to some creative marketing professionals. Here are four tips for adapting to wield data for insi…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses
Course of the Month9 days, 19 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question