English 中文(简体)
进入春天中心 DI j豆
原标题:Accessing Spring MVC DI beans from jsp

在多国公司的一些框架中,如果你希望执行某些守则,并提出一些部分观点,你可以把控制者的行动称作观点。 我不相信在春天MVC会采取什么正确做法。

我想有一套共同财产调查模板。 其中一部分将排在网页上,有些是小部分,如gin子、 log子、 men云等。 每一个构成部分都需要一些神职人员或控制人员采取行动,将一些数据输入GiAndModel,以便使用这一数据。

问题是,我不想在每次呼吁中确定所有这些目标。 我的登记册控制员只关心登记处理。 因此,现在,我如何正确? 我如何从中呼吁移民与发展协会的教友或控制者编写部分意见? 或者,我是否应当绘制一些地图? 还是我从完全错误的角度来处理这个问题?

最佳回答
问题回答

IMO add use exposedContextBeanNames in viewResolver bean configuration (there is also possibility to use global flag and it s rather not recommended)

<bean id="viewResolver"
    class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="exposedContextBeanNames">
 <list>
  <value>beanName</value>
 </list>

参考文件

${beanName.property}

A critical part of using InternalResourceViewResolver seems to be that Spring needs to be involved in the code flow when the jsp page is being processed. If you re accessing the jsp page directly or otherwise bypassing any Spring-based action (e.g. perhaps by internally forwarding to a jsp page due to login configuration in web.xml), then that won t work.

However, it is possible to configure your application so that certain beans are accesible to anything that can get to the ServletContext (aka applicationScope) through the use of the ServletContextAttributeExporter class.

在你的春季组合中,增加:

<bean id="mybean" .../>
<bean class="org.springframework.web.context.support.ServletContextAttributeExporter">
    <property name="attributes">
        <map>
            <entry key="attrname" value-ref="mybean"/>
        </map>
    </property>
</bean>

之后,在菲律宾统计局的网页上,你可以与下列人士接触:

${applicationScope.attrname}

或者如果你知道你没有“对象名称”这一更具体的范围,那就是:

${attrname}

很显然,这只胜数能够提及申请或会议范围大豆,但是如果你需要使用单一吨灯塔,那是不起作用的。

您可使用<条码> 代谢:

...
<spring:eval expression="@properties.getProperty( myProp )" var="myProp" />
${myProp}
...

@properties 是你在春天情况下的财产名称。 请注意,这一办法不使用<代码>exposedContextBeanNames,因此可以用蒂尔斯意见(例如TilesViewResolver<>/code>没有这种适当性)。

永远不能从小 views观点中获取商业成分;像小片一样,可以把 mu观点结合起来。 Jsps也不应直接援引控制器方法

采用基于说明的办法解决共同财产制度中使用春季豆的问题。

Spring MVC + JSP Functions:

@Bean
public ViewResolver tilesViewResolver() {
  final UrlBasedViewResolver = new UrlBasedViewResolver();
  ...
  viewResolver.setExposeContextBeansAsAttributes(true);
  viewResolver.setExposedContextBeanNames("myBean");
  return viewResolver;
}

在我的发言中:

<c:set var="myBeanData" scope="request" value="${myBean.myMethod()}"/>
<a id="id" href="${myBeanData}">Link</a>




相关问题
Check session from a view in CodeIgniter

What is the best way to check session from a view in CodeIgniter, it shows no way in their user guide, otherwise I will have to make two views on everything, which is kinda weird...still a newbie to ...

How to create a submit button template in Oracle APEX?

I m trying to create a template for a button in Oracle APEX but I don t seem to have access to the appropriate substitution strings to make it work. For non-templated buttons APEX seems to insert a ...

list of controls with templates in silverlight

Does anyone know where to find a list of controls that you can set the template on in Silverlight? I ve wasted several hours now trying to create control templates only to find that the control doesn ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Load ruby on rails template from database

I wonder if there is a way for me to store ruby on rails view files into database store and have that fetched directly from there. The reason is I want to create a CMS with all the user data stored in ...

Templated HTML Editor

I m looking for a HTML editor that kinda supports templated editing or live snippets or something like that. Background: I m working on a website for a friend. As there are no specifications what the ...

Dreamweaver changing path to site s reference instead of local

I have noticed recently, when I apply a template to a new HTML website, all the relative paths are pointed to my local files, example: file:///C|/webstuff/files but I cannot set them to relative paths ...

WPF ListView : Header styling

I want to have a ListView with columns and a particular style: The background for ALL column headers should be transparent except when the mouse is over in one of them. When this happends, the ...