使用Java提交表单
我有一个 JSF 1.2 登录页面 (login.xhtml),它有 2 个子表单 - menuForm、loginForm。
使用浏览器,我可以通过单击登录表单中的“登录”按钮从登录页面导航到productList.xhtml 页面。
....为了允许Google Crawler 爬行需要登录的页面,我尝试在loginForm 上测试使用Java 程序提交的表单,看看是否可以检索productList.xhtml 页面。
login.xhtml 页面中的隐藏字段(从浏览器查看源代码)包括以下内容: 用户名 密码 自动滚动 登录表单 登录按钮 javax.faces.ViewState
我已在 Java 程序中提交了上面的所有值(javax.faces.ViewState 除外),但我在响应中始终只收到 login.xhtml 页面。这是为什么呢?
我无法提交 javax.faces.ViewState,因为当从 Java 程序进行提交时,服务器端没有表单的状态。如何提交还没有视图状态的表单?
I have a JSF 1.2 login page (login.xhtml) that has 2 sub-forms - menuForm, loginForm.
Using a browser, I am able to navigate from the login page to a productList.xhtml page by clicking on the Login button within the loginForm.
....
For allowing the Google Crawler to crawl through my pages that require login, I am trying to test a form submit with a Java program on the loginForm to see if I can retrieve the productList.xhtml page.
The hidden fields (View Source from browser) in the login.xhtml page includes the following:
username
password
autoScroll
loginForm
loginButton
javax.faces.ViewState
I have submitted all the values from above (except the javax.faces.ViewState) in my Java program, but I keep getting only the login.xhtml page back in my response. Why is this?
I cannot submit the javax.faces.ViewState because there is no state on the server-side for the form when a submit happens from the Java program. How do I submit a form that does not yet have a view state?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
登录需要会话(基本上是:cookie)。但网络爬虫不维护会话(基本上:它们不维护cookie)。所以就到这里结束了。您必须删除登录表单并将所有导航命令链接替换为普通链接,以便让任何网络爬虫索引您的页面。
顺便说一句,我无法理解为什么您希望使受限制的页面可爬行(因此:公开可用)。为什么首先要登录?
因为你省略了视图状态字段。 JSF 将不会处理表单提交。对于一部分来说,这是针对 CSRF 攻击的防护措施,而对于其他部分来说,这是因为 JSF 是一个基于有状态组件的 MVC 框架。
您需要维护会话(基本上:在后续请求中从服务器发送回所有 cookie),或者在 < code>web.xml 到
client
并且,您还需要将视图状态隐藏字段与表单提交请求一起传递。A login requires a session (basically: a cookie). But web crawlers does not maintain the session (basically: they do not maintain cookies). So it ends up here. You have to remove the login form and replace all navigation commandlinks by normal links in order to let any webcrawler index your pages.
It's by the way beyond me why you would like to make restricted pages crawlable (thus: publicitly available). Why is the login there in first instance?
Because you omitted the view state field. JSF won't process the form submit then. For a part, this is a safeguard against CSRF attacks and for other part, this is because JSF is a stateful component based MVC framework.
You need to either maintain the session (basically: send all cookies from the server back in subsequent requests), or to set the state saving method in
web.xml
toclient
and you also need to pass the view state hidden field along with the form submit request.