2012-02-08 10 views
0

ここに質問があります。私は、レセレットのために4つのクラスを作成しました。しかし、私はブラウザでhttp://localhost:8182/firstSteps/helloを押すと、私はUserName = userName、Password =パスワードを返します。どのクラスを変更する必要がありますか? http://localhost:8080/restletTest?p1=abc&p2=defウェブブラウザから値を返す

package firstStep; 

    import org.restlet.Component; 
    import org.restlet.data.Protocol; 

public class Mainone { 
    public static void main(String[] args) throws Exception { 

     // Create a new Component. 
     Component component = new Component(); 

     // Add a new HTTP server listening on port 8182. 
     component.getServers().add(Protocol.HTTP, 8182); 

     // Attach the sample application. 
     component.getDefaultHost().attach("/firstSteps", new FirstStepsApplication()); 

     // Start the component. 
     component.start(); 

    }} 


package firstStep; 

import org.restlet.Application; 
import org.restlet.Restlet; 
import org.restlet.routing.Router; 

public class FirstStepsApplication extends Application{ 

    public Restlet createInboundRoot(){ 
     Router router = new Router(getContext());  
     router.attach("/hello",FirstServerResource.class); 
     return router; 
    }} 

package firstStep; 

import org.restlet.resource.Get; 
import org.restlet.resource.ServerResource; 

public class FirstServerResource extends ServerResource { 

    Contact contact = new Contact("userName","Password"); 
    //Contact contactTwo = contact.retrieve(); 

// @Get 
// public Contact retrieve() { 
//  return contact; 
// } 

    @Get 
    public String toString() { 
     return contact.toString(); 

    } 

} 


package firstStep; 

public class Contact { 
    private String userName; 
    private String password; 

    //Constructor 
    public Contact(String userName,String password){ 
     this.userName = userName; 
     this.password = password; 
    } 

    public Contact retrieve(){ 
     System.out.println("Contact retrieve():"+this.userName+"|"+this.password); 
     return this; 
    } 

    public String toString(){ 
     return "Username:\t"+this.userName+"\nPassword:\t"+this.password;  
    } 

    public String getUserName() { 
     return userName; 
    } 

    public void setUserName(String userName) { 
     this.userName = userName; 
    } 

    public String getPassword() { 
     return password; 
    } 

    public void setPassword(String password) { 
     this.password = password; 
    }} 

緊急にヘルプが必要です。ありがとう。

答えて

0

あなたがhttp://localhost:8182/firstSteps/hello を襲ったとき、接触の@Get toString() -methodが呼び出され、出力

UserName: userName 
Password: Password 

が正しいです。 したがって、値はサーバーから正しく戻されます。

他に何をしますか?

関連する問題