加载页面时的Struts2动作类 [英] Struts2 action class when loading page

查看:87
本文介绍了加载页面时的Struts2动作类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一定想念一些东西,希望有人能使我挺直.我继承的Webapp使用struts2和JSP页面,我想使用此布局管理器对其进行组织( http://igniteui.com/layout-manager/border-layout-markup ).左侧将有一个菜单,该菜单具有将内容加载到中心的链接,而主"页面(页眉,页脚,左侧菜单)保持不变,我认为这符合SPA原则.中间的内容"将是JSP页面,这些页面的表单带有在用户操作后提交的输入字段.

I must be missing something that I hope someone can set me straight. The webapp I inherited uses struts2 and JSP pages, and I want to organize it using this layout manager ( http://igniteui.com/layout-manager/border-layout-markup ). There will be a menu on the left which has links that will load content into the center, while the 'main' page (header, footer, left menu) stays put which I believe fits the SPA principles. The 'content' in the middle will be JSP pages that have forms with input fields that are submitted after user actions.

我不明白的是Struts动作如何适应这一点.该应用程序具有在struts.xml中定义的操作,并且在提交该页面/表单时可以正常工作.但是,何时将新的JSP加载到主页的内容部分中呢?与该加载相关联的方式或动作是什么?

What I'm not understanding is how struts actions fit into this. The app has actions that are defined in struts.xml and that works fine when that page/form is submitted. But what about when the new JSP is loaded into the content section of the main page? How or what action is associated with that loading?

当前,主页使用iframe作为内容:

Currently the main page uses an iframe for the content :

<div class="center">
    <iframe id="ifrmContent" name="iframe" src="jspDefaultContent.jsp" </iframe>
</div>

在左侧菜单中单击链接时,这就是我切换内容的方式:

and when a link is clicked in the left menu this is how I switch content :

$("#ifrmContent").attr('src','jspNewContent.jsp');

首先,我应该问一下这是否是正确的/最佳方法,因为我已经看到/听说使用iframe不理想.

First I should ask if that is the right/best way to do this, as I've seen/heard that using iframes is not ideal.

第二,特定的问题是,与此新的JSP内容页面加载没有关联的动作".因此,用于用数据库中的数据填充某些s:select元素列表的OGNL不起作用.具体来说,这将起作用:%{@ com.my.class@countryList}",因为它在该Java服务器类中调用了一个静态变量,但是它不:%{getCities()}",因为它要调用一个动作类的方法..并且没有.它既不会调用MAIN页面操作,也不会调用内容页面操作类.

Second, the specific problem is that there is no 'action' associated with this new JSP content page loading. So the OGNL that was used to fill in some s:select element lists with data from the database does not work. Specifically this WILL work : "%{@com.my.class@countryList}" because its calling a static variable within that Java server class, but this does NOT : "%{getCities()}" as it is looking to call a method of an action class.. and there is none. It doesn't call the MAIN page action, nor does it call the content page action class.

如何从菜单链接获取与正在加载的内容页面相关联的动作类?或者,鉴于我只想刷新/提交内容而不是刷新整个MAIN页面,该如何/应该如何组织以便我没有这些问题?

How can I get an action class associated to the content page I'm loading from a menu link? Or, how can/should this be organized so I don't have these problems, given that I only want to refresh/submit the content and not the entire MAIN page?

谢谢您的建议.

推荐答案

第一
您可以使用CSS将页面分为页眉,页脚,菜单,正文.这是一种轻量级的方法.这可以代替iframe达到您的目的.

First
You can use css to divide a page into header,footer,menu,body. This is a lightweight approach. This can replace iframe for your purpose.

  • iFrame会将框架作为单独的页面加载.如果您在主体区域中编写一个包含1个iframe的页面,则就像加载2个页面一样,这会使页面加载速度变慢.
  • 先加载iframe内容,然后呈现网页内容,这就是为什么您会发现某些网页中的某些内容被快速填充而其他内容的加载却被延迟的原因.
  • 您可以使用iFrame加载广告,但是请避免使用它.

第二
如何从菜单链接获取与正在加载的内容页面相关的动作类?

您可以将任何JSP页面的操作项指向操作servlet(struts.xml).您必须将一个动作从该JSP页面指向您要在Struts.xml中映射的动作.

它是与基本struts2程序相同的模型. 如果您对支撑杆流有基本了解,可以这样做.

鉴于我只想刷新/提交内容而不是整个MAIN页面,因此如何/应该如何组织这些问题,所以我没有这些问题?

如果是这种情况,则不应在主体部分中使用iframe进行内容加载. iframe会为每个HTTP请求加载整个网页.
答案是将AJAX与jQuery一起使用

Second
How can I get an action class associated to the content page I'm loading from a menu link?

You can point action items of any of your JSP pages to the action servlet(struts.xml). You have to point an action from this JSP page to the action you wanted to map in Struts.xml.

It is the same model as the basic struts2 program. if you have a basic understanding of struts flow you can do this.

how can/should this be organized so I don't have these problems, given that I only want to refresh/submit the content and not the entire MAIN page?

If this is the case you shouldnot use iframes for content loading in body section. Iframe's will loading the entire webpage for each HTTP request.
Answer for this is to use AJAX with jQuery

这篇关于加载页面时的Struts2动作类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆