2012-02-15 2 views
0

사용자가 URL을 입력 할 때 전달 된 매개 변수를 검색하는 데 도움이 필요합니다. http://localhost:8182/trace/abc/def?param=123 매개 변수가 전달 된 곳은 123입니다. 123을 표시하려면 어떻게해야합니까?url에 전달 된 매개 변수를 검색하여 restlet을 사용하여 웹 브라우저에서 값을 반환

Part05 
import org.restlet.Component; 
//import org.restlet.Server; 
import org.restlet.data.Protocol; 
import org.restlet.resource.Get; 
import org.restlet.resource.ServerResource; 


public class Part05 extends ServerResource { 

    public static void main(String[] args) throws Exception { 
     // Create the HTTP server and listen on port 8182 
     //new Server(Protocol.HTTP, 8182, Part05.class).start(); 

    // TODO Auto-generated method stub 
     // Create a new Restlet component and add a HTTP server connector to it 
     Component component = new Component(); 
     component.getServers().add(Protocol.HTTP, 8182); 

     // Then attach it to the local host 
     component.getDefaultHost().attach("/trace", Part05.class); 

     // Now, let's start the component! 
     // Note that the HTTP server connector is also automatically started. 
     component.start(); 
    } 
    @Get 
    public String toString() { 

     // Print the requested URI path 
     return "Resource URI : " + getReference() + '\n' + "Root URI  : " 
       + getRootRef() + '\n' + "Routed part : " 
       + getReference().getBaseRef() + '\n' + "Remaining part: " 
       + getReference().getRemainingPart() ; 
    } } 

홈페이지

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

public class Main { 

    /** 
    * @param args 
    */ 
    public static void main(String[] args) throws Exception 
    { 
     // TODO Auto-generated method stub 
      // Create a new Restlet component and add a HTTP server connector to it 
      Component component = new Component(); 
      component.getServers().add(Protocol.HTTP, 8182); 

      // Then attach it to the local host 
      component.getDefaultHost().attach("/trace", Part05.class); 

      // Now, let's start the component! 
      // Note that the HTTP server connector is also automatically started. 
      component.start(); 
    }} 
: 웹 browser.Which 자바 클래스 내가 검색 한 웹 페이지의 매개 변수를 반환하기 위해 변경해야합니다 여기에

내가 가지고있는 코드는 내가 가진3210

출력 : 자원 URI : http://localhost:8182/trace/abc/def?param=123 남은 부분은 :/ABC/DEF PARAM = 123

도움이 절실히 필요합니다! 감사

답변

0

난 당신이 Restlet 프레임 문서 및 online help

다음

당신이 ServerResource 클래스의 @Get 방법 내에서 매개 변수를 액세스 할 수있는 방법 읽으십시오 : (예 위의 문서 링크에서 빌린를)

Form form = request.getResourceRef().getQueryAsForm(); 
for (Parameter parameter : form) { 
    System.out.print("parameter " + parameter.getName()); 
    System.out.println("/" + parameter.getValue()); 
} 

매개 변수 값의 문자열 표현 (예 : 123)을 반환 할 수 있습니다. 대신 말한다면

당신의 (a String 등) 전체 쿼리 문자열을 얻을 수 있습니다 :

request.getResourceRef().getQuery(); // or getQuery(true) if you wish to have URI decoding

하지만 당신은 자신이이 경우에 경우 값을 구문 분석해야합니다. 전자는 매개 변수 목록에 액세스 할 수있게 해 주므로 더 좋습니다.

이들은 Javadocs

에 설명되어 있습니다.