Java Jersey HTTP, cannot receive browser parameters

Asked

Viewed 67 times

0

Hello I would like to receive a parameter from the browser and print using webservices with Jersey, however the parameter does not reach my method, it is not to be printed.

XML

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <display-name>webService</display-name>
    <listener>
        <description>
        Used to cleanup when a session is destroyed</description>
        <display-name>ZK Session cleaner</display-name>
        <listener-class>org.zkoss.zk.ui.http.HttpSessionListener</listener-class>
    </listener>

        <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
        <welcome-file>index.zul</welcome-file>
    </welcome-file-list>

<servlet>
        <servlet-name>Jersey Web Application</servlet-name>
        <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Jersey Web Application</servlet-name>
        <url-pattern>/rest/*</url-pattern>
    </servlet-mapping>

</web-app>

Java method that takes the parameter and should print in the browser:

package mz.webservice.testar;

import javax.websocket.server.PathParam;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;

@Path("/hellowold")
public class Testando {

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    @Path("/{id}")
    public  String GettingHellowold(@PathParam("id") String id) {
        String st=id;

        return "Nome: "+st;
    }

}

Result in browser

inserir a descrição da imagem aqui

1 answer

0

Hello consigui do implementation, Thanks for the help.

package mz.webservice.testar;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.ws.rs.Consumes;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import com.google.gson.Gson;

@Path("/hellowold")
public class Testando {


    //http://localhost:8080/webService/rest/hellowold/primeiro?conta=123456&codigo=00000123

    @GET
    @Path("/primeiro")
    public Response getEmployeeQueryDefault( @QueryParam("conta") String conta, @QueryParam("codigo") String codigo) {
    String response;
    Gson  g=new Gson();
    Person person=new Person();
    person.setCodigo(codigo);
    person.setConta(conta);
    response=g.toJson(person);
    try {

    } catch (Throwable e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    return Response.status(200).entity(response).build();
    }

}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.