473,385 Members | 1,796 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Using global object to save user information

13
Am trying to use my user object to hold one value after the user has logged in my website. when loging in the user object id is set using user.setid("id");

Once this is done. I want to use user.getid(); in a differernt method to update user record.

I cant get the user object to hold the same value between the two methods

Expand|Select|Wrap|Line Numbers
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5.  
  6. package user;
  7. import java.sql.ResultSet;
  8. import java.sql.SQLException;
  9. import java.util.Random;
  10. import javax.jws.WebMethod;
  11. import javax.jws.WebParam;
  12. import javax.jws.WebService;
  13.  
  14. /**
  15.  *
  16.  * @author Yeneneh Mulatu
  17.  */
  18. @WebService()
  19. public class userWebService {
  20. private User user= new User ();
  21. private Random pwd = new Random();
  22. private ResultSet rs;
  23. private conn mydb = new conn("root","");
  24.  
  25.     /**
  26.      * Web service operation
  27.      */
  28.     @WebMethod(operationName = "login")
  29.     public String login(@WebParam(name = "email")
  30.     String email, @WebParam(name = "password")
  31.     String password) {
  32.         String login=null;
  33.         try{
  34.  
  35.         mydb.open("class_Alert");
  36.          rs = mydb.get("SELECT id,email,password FROM user WHERE email='"+email+"'and password="+password+" ");
  37.         //TODO write your implementation code here:
  38.         if(rs!=null){
  39.             user.setID(rs.getString("id"));
  40.             user.setUserlname(email);
  41.             login=user.getID();
  42.         }
  43.         else login=null;
  44.         }
  45.         catch ( SQLException sqle){
  46.                sqle.getMessage();
  47.  
  48.            }
  49.  
  50.         return login;
  51.     }
  52.  
  53.     /**
  54.      * Web service operation
  55.      */
  56.     @WebMethod(operationName = "admin")
  57.     public Object admin(int select) {
  58.  
  59.  
  60.         mydb.open("class_Alert");
  61.         rs=mydb.get("SELECT * FROM user WHERE id="+user.getID());
  62.          try{
  63.             // while (rs.next()){
  64.                 user.setID(rs.getString("id"));
  65.                 user.setUsername(rs.getString("fname"));
  66.                 user.setUserlname(rs.getString("lname"));
  67.                 user.setUserphone(rs.getString("phone"));
  68.                 user.setUseremail(rs.getString("email"));
  69.                 user.setRole(rs.getString("role"));
  70.  
  71.             // }
  72.  
  73.          } catch ( SQLException sqle){
  74.  
  75.          }
  76.         switch (select) {
  77.             case 1:  return user.getID();
  78.             case 2:  return user.getUsername();
  79.             case 3:  return user.getUserlname();
  80.             case 4:  return user.getUserphone();
  81.             case 5:  return user.getUseremail();
  82.             case 6:  return user.getRole();
  83.         }
  84.         //TODO write your implementation code here:
  85.        return user.toString();
  86.     }
  87.  
Mar 17 '10 #1
2 2461
Frinavale
9,735 Expert Mod 8TB
If your web service requires user information in order to work properly then your "website" that is using (consuming) the web service must provide the user information to the web service.

So, a user logs into your website.

You store their user information somewhere accessible to you for the duration of the time that they are logged in....like Session or something.

When the user does something that requires the web service, you provide the information required by the web service in order for it to work.

-Frinny
Mar 18 '10 #2
Yene
13
Thank you for your help
Mar 31 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: kyma via .NET 247 | last post by:
Hi, I haveto use VB to create a form that reads an exisiting XML fileand then allows updates via the VB form. My problem is that I was able to get VB to read a simple XML file(people.XML), but...
5
by: Rob | last post by:
Help me, I'm just beginning with programming in Access 2000. I've tried the http://www.mvps.org/access/api/api0001.htm but it won't work in Access. What am i doing wrong. I don't have...
1
by: Daveyk0 | last post by:
Hello there, I have a front end database that I have recently made very many changes to to allow off-line use. I keep copies of the databases on my hard drive and link to them rather than the...
4
by: Jae | last post by:
I'm writing a web application that exports and imports excel files. The application gets a list of users and their info and displays it in a datagrid .The user then selects to save the file as a...
4
by: wh | last post by:
I really just need some reassurance that I'm doing the right thing really. Here goes... I have an object which needs to be available to all sessions. This is being created in the...
22
by: fd123456 | last post by:
Hi Tom ! Sorry about the messy quoting, Google is playing tricks on me at the moment. > Global.asax is where you normally have the Global Application > and Session variables and code to...
3
by: kingski | last post by:
I have a web site created with ASP.NET 1.1. availability Global.asax: protected void Application_PreRequestHandlerExecute(Object sender, EventArgs e)
1
by: Anonieko | last post by:
Understanding and Using Exceptions (this is a really long post...only read it if you (a) don't know what try/catch is OR (b) actually write catch(Exception ex) or catch{ }) The first thing I...
1
by: linda.chen | last post by:
I am not an experienced asp.net developer. A while ago I created a website related to my other project, which requires login before start. I created a global.asax file, set the user name and a...
21
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Uploading files from a local computer to a remote web server has many useful purposes, the most...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.