GameBuilder
GameBuilder

Reputation: 1189

How to use class in java

I am new to GWT and java Here is example to understand my problem

Code

  .Client

  Class A(){
// design Part with 2 text box for user name and password
//On click event of Button  asyncInterface is called (RPC) to create a session

service.getConnection(authentication, callback);// authentication is array with username password

}

on SERVER side

 .server
public class ServiceIMPL extends RemoteServiceServlet implements ServiceInterface{
     public String getConnection(String[] authentication) {
        connectionParameter = new ConnectionParameter(authentication,repositoryName);
        session=connectionParameter.getSession();
     }
 }

This Session is used to for adding deleting the folder in the repository.

the addFolder, getFolder,getDocment methods are written in same class as Session required to do so.Every thing is working fine.

Now i have to addDocument in the repository. For which i have design a servlet in server

 public class FileUpload extends HttpServlet implements Servlet {

// servlet is also working fine i have the content of file in buffer.
//but to add file in a repository I need Session which is in ServiceIMPL Class
//if I create a object of ServiceIMPL class then the authentication will be null
//Without Username and Pass word session cannot be created.
}

Please help me how to do it.

Upvotes: 0

Views: 187

Answers (2)

NewCodeLearner
NewCodeLearner

Reputation: 738

In Class ServiceImpl make the session public

    public Session session;

and in class File Upload

  private Session session = ServiceImpl.session;

I gurantee this will work. but this is not the good way of coding. wait till any Expert reply.

Upvotes: 1

Hilbrand Bouwkamp
Hilbrand Bouwkamp

Reputation: 13519

What kind of session do you use? If it is a HttpSession you can simply do request.getSession() from the HttpServletRequest request parameter in doGet in your FileUpload servlet.

Upvotes: 0

Related Questions