当用户通过搜索引擎请求 jsp 时,struts2 操作是否被调用
我刚刚开始做一个struts2项目。我已经看到了 struts 中动作的力量。 我只想知道几件事
1.当客户端通过搜索引擎请求页面时,服务器是否通过映射 jsp 的操作来引导请求? 2. 如果上述问题的答案是否定的,我们如何在操作类中设置渲染页面所需的所有 bean 属性? 3.如果上述问题的答案不是如何维护数据机密性,因为所有拦截器都是围绕操作构建的
I have just started working on a struts2 project. I have seen the power of actions in struts.
i just want to Know few things
1.When a client asks for a page through the search engine does the server direct the request through an action which maps the jsp?
2. If the ans to the above question is no how do we set-up all the bean properties in the action class required for rendering the page?
3.If the ans to the above question is no how to maintain data confidentiality as all interceptors are built around action
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您的 JSP 页面可公开访问并且用户直接访问它们(例如,从搜索引擎或书签),那么不会,您的操作不会被调用。
您的JSP 应放置在WEB-INF 目录下(例如/WEB-INF/jsp),以便用户无法直接访问它们。在 Struts2(任何其他 MVC 框架)中,JSP 只是视图层的模板,不应直接访问。
有几条评论回复问题中的答案之一通过在 WEB-INF 目录下移动 JSP 来强化这一点:
If your JSP pages are publicly accessible and a user goes to them directly (e.g., from a search engine or bookmark), then no, your action would not be invoked.
Your JSPs should be placed under the WEB-INF directory (e.g., /WEB-INF/jsp) so that users cannot get to them directly. In Struts2 (any many other MVC frameworks), JSPs are only the templates for your view layer and should not be accessed directly.
There are several comments in reply to one of the answers in Problem with moving JSPs under WEB-INF directory that reinforce this:
Struts 的工作方式是,它有一个调度程序 servlet,它读取传入请求的路径并决定将它们发送到哪个操作,然后执行该操作并将其转发到 jsp。所以action是否被调用取决于客户端点击的url是什么,如果是映射到struts中action的url,那么它将调用该action,否则不会。
The way Struts works is that it has a dispatcher servlet that reads the path of incoming requests and decides which action to send them to, then the action executes and forwards to a jsp. So whether the action gets called depends on what the url is that the client is clicking on, if it is a url that is mapped to an action in struts then it will call the action, otherwise not.