2012-02-08 129 views
0

我在这里有一个问题。我为restlet创建了4个类。但是,当我点击浏览器时,它返回我UserName =用户名,密码=密码http://localhost:8182/firstSteps/hello。我应该更改哪个类以便获得预期的URL,例如 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; 
    }} 

急需帮助。谢谢。

回答