当用户在 URL 中键入 http://localhost:8182/trace/abc/def?param=123时,我需要帮助来检索传递的参数 ,其中传递的参数是 123。如何让 123 显示在网络上浏览器。为了检索和返回网页中的参数,我应该更改哪些 java 类
这是我拥有的代码:
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();
}}
我得到的输出:资源 URI:http://localhost:8182/trace/abc/def?param=123 剩余部分:/abc/def?param=123
急需帮助!!谢谢