Wicket http post, get raw data from servletrequest?

后端 未结 1 565
忘了有多久
忘了有多久 2021-01-07 12:31

I try do POST some data to a Wicket WebPage. This works fine if the data is in a form. However, I want to post the data with jQuery\'s ajax-post. I am unable to get this dat

1条回答
  •  走了就别回头了
    2021-01-07 13:14

    It seems Page does something to the post-parameters.

    The solution for my problem is to use a Resource.

        public class MyResource extends AbstractResource
        @Override
        protected ResourceResponse newResourceResponse( Attributes attributes )
        {
    
            ResourceResponse resourceResponse = new ResourceResponse();
            resourceResponse.setContentType( "text/json" );
            resourceResponse.setTextEncoding( "utf-8" );
    
            HttpServletRequest request = (HttpServletRequest) attributes.getRequest().getContainerRequest();
    
            try
            {
                this.json = IOUtils.toString( request.getInputStream() );
            }
            catch ( IOException e )
            {
                e.printStackTrace();
            }
    
            resourceResponse.setWriteCallback( new WriteCallback()
            {
                @Override
                public void writeData( Attributes attributes ) throws IOException
                {
                    OutputStream outputStream = attributes.getResponse().getOutputStream();
                    Writer writer = new OutputStreamWriter( outputStream );
    
    
                    writer.write( MyResource.this.json );
                    writer.close();
                }
            } );
    
            return resourceResponse;
        }
    

    0 讨论(0)
提交回复
热议问题