67,550
社区成员




<body>
<jsp:forward page="showIndex.action"></jsp:forward>
</body
<!-- struts2的过滤器 -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.action</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>struts2</welcome-file>
</welcome-file-list>
<default-action-ref name="index" />
<action name="index" class="com.action.IndexAction">
<result name="success">/index.jsp</result>
</action>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>struts2</welcome-file>
</welcome-file-list>
<package name="default" namespace="/" extends="struts-default">
<default-action-ref name="index" />
<action name="index" class="com.envch.action.IndexAction">
<result name="success">/index.jsp</result>
</action>
</package>
package com.envch.action;
import java.util.ArrayList;
import java.util.List;
import com.envch.model.News;
import com.envch.model.Product;
import com.envch.model.Ptype;
import com.envch.service.CompanyService;
import com.envch.service.NewsService;
import com.envch.service.ProductService;
import com.envch.util.PageVo;
import com.envch.util.SearchVo;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class IndexAction extends ActionSupport {
private NewsService ns = new NewsService();
private ProductService ps = new ProductService();
private CompanyService cs = new CompanyService();
private PageVo pageVo = new PageVo();
private SearchVo sv = new SearchVo();
private News news;
public News getNews() {
return news;
}
public void setNews(News news) {
this.news = news;
}
public PageVo getPageVo() {
return pageVo;
}
public void setPageVo(PageVo pageVo) {
this.pageVo = pageVo;
}
public SearchVo getSv() {
return sv;
}
public void setSv(SearchVo sv) {
this.sv = sv;
}
@Override
//重写struts的execute
public String execute() throws Exception {
List productList = ps.getProductList(pageVo, sv);
Product product = new Product();
List ptypeList = new ArrayList();
Ptype p = new Ptype();
if(productList != null){
for(int i=0; i<productList.size(); i++){
product = (Product)productList.get(i);
p = ps.getPtype(product.getPtype());
ptypeList.add(p);
}
}
//拿到你需要的List
ActionContext.getContext().put("newsList", ns.getNews(pageVo, sv));
ActionContext.getContext().put("productList", productList);
ActionContext.getContext().put("plist", ptypeList);
ActionContext.getContext().put("companyList", cs.getCompanyList());
return SUCCESS;
}
}