0

External POST form submit to ZK's URL without explicit zul page

asked 2020-09-04 21:09:58 +0800

mikrobe gravatar image mikrobe
63 1 5

updated 2020-09-04 21:15:40 +0800

I need to submit a POST form to a zk application but I cannot retrieve the parameters because the request is always empty. My POST form looks like:

<form method="post" action="http://localhost/myapp">

and my ZK app has an Initiator that retrieves form's parameters. I spent 3 days banging my head against this problem, trying to understand if I submitted a wrong form, or whether it was the Initiator class or even Apache Shiro that could clean up the request or anything else.

Today I found out that if I submit a POST form to a url that includes the zul page name (e.g http://localhost/myapp/index.zul) it works, but if I don't specify the zul page, it doesn't.

I did a very simple test, with just a index.zul and a ViewModel: no Initiator, no Shiro no nothing and I could replicate that behaviour. Is there any explanation for this or is there any solution that allows me to not specify the zul page?

Thank you

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted
1

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

cor3000 gravatar image cor3000
5399 2 7
ZK Team

updated 2020-09-07 18:54:53 +0800

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 (common surprise).

Described in 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 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.

https://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.

link publish delete flag offensive edit

Comments

Thank you a lot for your exaustive answer. So I just have to blame my ignorance.

mikrobe ( 2020-09-07 20:21:33 +0800 )edit

I glad this helped. Nothing about "ignorance", it's more about "awareness", those specs are very boring to read and contain lots of weird surprises. In fact I just found out about that detail after you asked your question. So thanks for making me search for this -> I learned something as well. :)

cor3000 ( 2020-09-08 09:12:54 +0800 )edit

Thank you Robert, very kind of you.

mikrobe ( 2020-09-08 14:52:31 +0800 )edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2020-09-04 21:09:58 +0800

Seen: 8 times

Last updated: Sep 07

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