简体   繁体   English

struts 2应用程序无需JSP即可呈现结果。 这怎么可能?

[英]struts 2 application renders results without JSP. How is this possible?

I am following the tutorial on struts 2 at http://www.simplecodestuffs.com/integrating-jquery-datatable-with-struts2-using-ajax-to-implement-gridview/ 我正在http://www.simplecodestuffs.com/integrating-jquery-datatable-with-struts2-using-ajax-to-implement-gridview/上关于struts 2的教程中

I understood the core concepts like using POJO action classes struts.xml configurations etc. But whats troubling me is in this tutorial, there is a jsp result mentioned in struts.xml called " grid.jsp". 我了解了诸如使用POJO操作类struts.xml配置等的核心概念。但是令我困扰的是本教程中,在struts.xml中提到了一个jsp结果,称为“ grid.jsp”。 But this page is not at all present in the application and it still works. 但是此页面在应用程序中根本不存在,并且仍然有效。

How can this happen? 怎么会这样 does struts 2 generate some jsp templates? struts 2会生成一些jsp模板吗? Please check the attached screenshot. 请检查随附的屏幕截图。 It has the project structure and struts.xml. 它具有项目结构和struts.xml。

I have tried various books and tutorials and google searches but this topic has never been discussed. 我尝试过各种书籍和教程以及Google搜索,但是从未讨论过该主题。 Please help. 请帮忙。 I would like to learn the flow from when the request reaches the action class. 我想从请求到达动作类时开始学习流程。

These kind of examples are also present in struts2 showcase. 这些示例也出现在struts2展示柜中。

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
    <package name="default" extends="json-default">
        <action name="dataTablesAction" class="com.action.GridViewAction">
            <result type="json">grid.jsp</result>
        </action>
    </package>

</struts>

项目结构和struts.xml

@zapl already answered you, I'll delete this answer if he will post his comments as an answer. @zapl已经回答了您,如果他将其评论作为答案,我将删除此答案。

When you write 当你写

 <result type="json">grid.jsp</result>

it will be translated to 它将被翻译成

 <result name="success" type="json"></result>

"success" will be added because of Intelligent Default ("success" is taken if no name specified) and the entire Action will be serialized into JSON, because that's how the JSON plugin works . "success"将因智能默认的添加(“成功”时,如果没有指定名称取)和整个行动将被序列化JSON成,因为那是JSON插件是如何工作的 You can specify a root object, but you can't specify a JSP, because JSP != JSON, and because raw text (like a jsp name) is not expected to be found there in the config. 您可以指定一个root对象,但不能指定一个JSP,因为JSP!= JSON,并且因为在配置中不会在其中找到原始文本(如jsp名称)。 Your grid.jsp will be simply ignored and cropped at all (not tested, but I'm pretty sure). 您的grid.jsp将会被完全忽略和裁剪(未经测试,但是我很确定)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM