I am trying to output an Excel file as the view in Spring Roo 1.0.2 What is the quickest way to do this? (Do I have to add new mapping etc?) At the moment I am using the default Roo AjaxUrlBasedViewResolver.
谢谢 (xiè xiè)
I am trying to output an Excel file as the view in Spring Roo 1.0.2 What is the quickest way to do this? (Do I have to add new mapping etc?) At the moment I am using the default Roo AjaxUrlBasedViewResolver.
谢谢 (xiè xiè)
我不认为有一个特定的“Roo”做法来做这个,但是Spring MVC有一个使用Apache POI的AbstractExcelView类,不会造成任何问题-我认为这是你所能期望的最好的。
首先创建一个视图类,该类扩展AbstractExcelView并实现buildExcelDocument方法:
import org.springframework.web.servlet.view.document.AbstractExcelView;
public class XlsView extends AbstractExcelView {
@Override
protected void buildExcelDocument(
Map<String, Object> model, HSSFWorkbook workbook,
HttpServletRequest request, HttpServletResponse response) throws Exception {
//Apache POI code to set up the HSSFWorkbook goes here
response.setHeader("Content-Disposition", "attachment; filename="file.xls"");
}
}
然后将以下内容添加到您的webmvc-config.xml中。我认为位置无关紧要,但我将它放在我的TilesConfigurer列出的部分下面:
<bean id="excelViewResolver" class="org.springframework.web.servlet.view.XmlViewResolver">
<property name="order" value="1"/>
<property name="location" value="/WEB-INF/views/views-excel.xml"/>
</bean>
最后,在意见中提出以下意见:
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<bean name="XlsView" class="com.your.package.XlsView"/>
</beans>
In messages.properties: error.code=This is error message. This is next line of error message. Now, when I set "errors.rejectValue" with this "error.code" for a form field, I cannot get the line ...
What is a simple way to resolve the path to a JSP file that is not located in the root JSP directory of a web application using SpringMVCs viewResolvers? For example, suppose we have the following web ...
please forgive me for this stupid questions. I just started developing web application using spring yesterday. The project that i worked on, have a multi staged form, that require users to complete ...
I m trying to get Tuckey UrlRewriteFilter to tidy up URLs for my webapp. One problem I ve got is that when spring-security notices that an anonymous user is trying to access a protected resource it ...
I have a spring dispatcher servlet with servlet-name "spring-mvc". The spring-mvc-servlet.xml appears as follows: <bean id="viewResolver" class="org.springframework.web.servlet.view....
I am having serious problems with code I have written with Spring so I have decided to start from scratch and ask for advice. Here are my requirements: When the page first loads I need a list of ...
I am new to Spring Web MVC.. Can I get some example or online link that shows me how to implement logout feature using spring web mvc ? I don t want to use the in built feature of spring security (i....
I am very new to Spring and I have a simpleFormController with 2 methods. referenceData() with is called when the page loads and onSubmitAction() which is called on the submit of a form. I am ...