当用户通过搜索引擎请求 jsp 时,struts2 操作是否被调用

发布于 2024-10-04 13:18:53 字数 192 浏览 2 评论 0原文

我刚刚开始做一个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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

清醇 2024-10-11 13:18:53

如果您的 JSP 页面可公开访问并且用户直接访问它们(例如,从搜索引擎或书签),那么不会,您的操作不会被调用。

您的JSP 应放置在WEB-INF 目录下(例如/WEB-INF/jsp),以便用户无法直接访问它们。在 Struts2(任何其他 MVC 框架)中,JSP 只是视图层的模板,不应直接访问。

有几条评论回复问题中的答案之一通过在 WEB-INF 目录下移动 JSP 来强化这一点:

我不确定struts,但是对于Spring,将JSP放在WEB-INF中是公认的做法,然后您的视图代码访问受保护的JSP。这还可以防止直接 HTTP 访问您的 JSP,以便您获得更好的访问控制。 -- jkf

Struts 也是如此。将 JSP 放在 WEB-INF 文件夹中被认为是一个好习惯。无论如何,我已经得到了答案。 -- 工匠

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:

I'm not sure about struts, but with Spring, it is accepted practice to put JSPs in WEB-INF and then your view code accesses the protected JSP. This also prevents direct HTTP access to your JSPs so you get better access controls. -- jkf

Same goes for Struts as well. It is considered a good practice to put JSPs in WEB-INF folder. Anyways, I have got my answer. -- craftsman

淡笑忘祈一世凡恋 2024-10-11 13:18:53

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文