我正在尝试在netbeans中创建Restuful Web服务。我去了new project -> Java Web -> Web Application
。之后,我右键点击并选择了Restful Web Services from patterns
。代码是:
import com.sun.xml.bind.v2.WellKnownNamespace;
import java.io.StringWriter;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriInfo;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PUT;
import javax.xml.bind.JAXB;
/**
* REST Web Service
*
* @author Administrator1
*/
@Path("welcome")
public class WelcomeRESTXMLResource {
@GET
@Path("{name}")
@Produces("application/xml")
public String getXml(@PathParam("name") String name){
String message = "Welcome "+ name;
StringWriter writer = new StringWriter();
JAXB.marshal(message, writer); //convert string to xml
return writer.toString();
}
}
因此,当我再次右键单击项目并单击项目中的test restful web services
和Web测试客户端时,会出现:
https://onedrive.live.com/redir?resid=B72DE0EFE15750DA!106&authkey=!AGTGB2BjQelAE9s&v=3&ithint=photo%2cpng
为什么会发生这种情况?