Revision history [back]

click to hide/show revision 1
initial version

answered 2020-09-07 18:40:28 +0800

cor3000 gravatar image cor3000

ZK Team

It's sad you spend 3 days on this.

By default a request to a path without a trailing "/" will be redirected to a path with a trailing "/" this redirect happens via GET without re-sending the original POST parameters. ​​ Described in (I never understood why they make it difficult to actually find those specs):

https://download.oracle.com/otndocs/jcp/servlet-3_1-fr-eval-spec/index.html

In secion 10.10:

  • A request URI of "/foo" will be redirected to a URI of "/foo/"
  • A request URI of "/foo/" will be returned as "/foo/index.html"

    (or index.zul as configured in your web.xml)

You can also observe this directly in the browsers developer tools. The original request to the url .../myapp contains the post parameters. The redirect to .../myapp/ doesn't.

image description

That's just how a servlet container naturally behaves according to the specification, when relying on the built in welcome-file mechanism.

ZK simply won't receive the POST-parameters if they are not contained in the request.

There are ways around this... the most direct one you already found... avoid the automatic redirect by specifying the zul file directly. Or what you didn't try ... appending the trainling "/" manually -> ../myapp/ avoids the redirect as well.

You can also add a rule to your nginx or apache-httpd to append the trailing "/" before contacting the servlet server. So you can have nicer urls (if that's a requirement). Or you can add a custom servlet or filter to do this inside the application server. Just be creative.

It's sad you spend 3 days on this.

By default a request to a path without a trailing "/" will be redirected to a path with a trailing "/" this redirect happens via GET without re-sending the original POST parameters. ​​ Described in (I never understood why they make it difficult to actually find those specs):

https://download.oracle.com/otndocs/jcp/servlet-3_1-fr-eval-spec/index.html

In secion 10.10:

  • A request URI of "/foo" will be redirected redirected to a URI of "/foo/""/foo/" -> (means 302 losing POST parameters)
  • A request URI of "/foo/" will be returned as "/foo/index.html"

    "/foo/index.html" -> (or index.zul as configured in your web.xml)

You can also observe this directly in the browsers developer tools. The original request to the url .../myapp contains the post parameters. The redirect to .../myapp/ doesn't.

image description

That's just how a servlet container naturally behaves according to the specification, when relying on the built in welcome-file mechanism.

ZK simply won't receive the POST-parameters if they are not contained in the request.

There are ways around this... the most direct one you already found... avoid the automatic redirect by specifying the zul file directly. Or what you didn't try ... appending the trainling "/" manually -> ../myapp/ avoids the redirect as well.

You can also add a rule to your nginx or apache-httpd to append the trailing "/" before contacting the servlet server. So you can have nicer urls (if that's a requirement). Or you can add a custom servlet or filter to do this inside the application server. Just be creative.

It's sad to hear you spend 3 days on this.

By default a request to a path without a trailing "/" will be redirected to a path with a trailing "/" this redirect happens via GET without re-sending the original POST parameters. parameters.

https://stackoverflow.com/questions/46582/response-redirect-with-post-instead-of-get ​​ Described in (I never understood why they make it difficult to actually find those specs):

https://download.oracle.com/otndocs/jcp/servlet-3_1-fr-eval-spec/index.html

In secion 10.10:

  • A request URI of "/foo" will be redirected to a URI of "/foo/" -> (means 302 losing POST parameters)
  • A request URI of "/foo/" will be returned as "/foo/index.html" -> (or index.zul as configured in your web.xml)

You can also observe this directly in the browsers developer tools. The original request to the url .../myapp contains the post parameters. The redirect to .../myapp/ doesn't.

image description

That's just how a servlet container naturally behaves according to the specification, when relying on the built in welcome-file mechanism.

ZK simply won't receive the POST-parameters if they are not contained in the request.

There are ways around this... the most direct one you already found... avoid the automatic redirect by specifying the zul file directly. Or what you didn't try ... appending the trainling "/" manually -> ../myapp/ avoids the redirect as well.

You can also add a rule to your nginx or apache-httpd to append the trailing "/" before contacting the servlet server. So you can have nicer urls (if that's a requirement). Or you can add a custom servlet or filter to do this inside the application server. Just be creative.

It's sad to hear you spend 3 days on this.

By default a request to a path without a trailing "/" will be redirected to a path with a trailing "/" this redirect happens via GET without re-sending the original POST parameters.

https://stackoverflow.com/questions/46582/response-redirect-with-post-instead-of-get ​​ Described in (I never understood why they make it difficult to actually find those specs):

https://download.oracle.com/otndocs/jcp/servlet-3_1-fr-eval-spec/index.htmlServlet Spec 3.1

In secion section 10.10:

  • A request URI of "/foo" will be redirected to a URI of "/foo/" -> (means 302 losing POST parameters)
  • A request URI of "/foo/" will be returned as "/foo/index.html" -> (or index.zul as configured in your web.xml)

You can also observe this directly in the browsers developer tools. The original request to the url .../myapp contains the post parameters. The redirect to .../myapp/ doesn't.

image description

That's just how a servlet container naturally behaves according to the specification, when relying on the built in welcome-file mechanism.

ZK simply won't receive the POST-parameters if they are not contained in the request.

There are ways around this... the most direct one you already found... avoid the automatic redirect by specifying the zul file directly. Or what you didn't try ... appending the trainling "/" manually -> ../myapp/ avoids the redirect as well.

You can also add a rule to your nginx or apache-httpd to append the trailing "/" before contacting the servlet server. So you can have nicer urls (if that's a requirement). Or you can add a custom servlet or filter to do this inside the application server. Just be creative.

It's sad to hear you spend 3 days on this.

By default a request to a path without a trailing "/" will be redirected to a path with a trailing "/" this redirect (302) happens via GET without re-sending the original POST parameters.

parameters (https://stackoverflow.com/questions/46582/response-redirect-with-post-instead-of-getcommon surprise ​​ ).

Described in (I never understood why they make it difficult to actually find those specs):

Servlet Spec 3.1 section 10.10:

  • A request URI of "/foo" will be redirected to a URI of "/foo/" -> (means 302 losing POST parameters)
  • A request URI of "/foo/" will be returned as "/foo/index.html" -> (or index.zul as configured in your web.xml)

You can also observe this th redirect directly in the browsers developer tools. image description

The original request to the url .../myapp contains the post parameters. The redirect to .../myapp/ doesn't.

image descriptionhttps://stackoverflow.com/questions/46582/response-redirect-with-post-instead-of-get

That's just how a servlet container naturally behaves according to the specification, when relying on the built in welcome-file mechanism.

ZK simply won't receive the POST-parameters if they are not contained in the request.

There are ways around this... the most direct one you already found... avoid the automatic redirect by specifying the zul file directly. Or what you didn't try ... appending the trainling "/" manually -> ../myapp/ avoids the redirect as well.

You can also add a rule to your nginx or apache-httpd to append the trailing "/" before contacting the servlet server. So you can have nicer urls (if that's a requirement). Or you can add a custom servlet or filter to do this inside the application server. Just be creative.

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More