Skip to Main Content

Java Development Tools

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

HttpServletRequest: servlet.doGet() receives empty request

elizabethRJan 16 2020 — edited Jan 20 2020

Oracle JDev 11.1.1.9.0

not a jdeveloper expert so any assistance would be greatly appreciated. We are developing React front end that will replace the jspx files but still want to use the original back end code as it interfaces with OIM.

I developed a servlet, to replace a managed bean,  that receives a request from a static react component. I can connect to the servlet but the request is empty. After some research, I was wondering if jdev is consuming the request somewhere before the servlet gets called. i have tried a number of things,  right now i am using request.getInputStream() to pull in the request but it is still empty. One source mentioned request.getReader() which didn't work either. Another mentioned using HttpServletRequestWrapper , another asked if JSF had already consumed the request? Yet another said to simply set the Content-Type.

    public void doGet(HttpServletRequest request,

                      HttpServletResponse response) throws ServletException,

                                                           IOException {

        StringBuilder stringBuilder = new StringBuilder(1000);

        Scanner scanner = new Scanner(request.getInputStream());

        while (scanner.hasNextLine()) {

            stringBuilder.append(scanner.nextLine());

        }

        String body = stringBuilder.toString();

        System.out.println("body: "+body);

.......

The below code is used in the managed beans but I'm not sure if i can actually use this in the servlet:

HttpServletRequest request = (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();

Comments

Post Details

Added on Jan 16 2020
3 comments
307 views