Re: How to forward request in struts 2.1.6?
xnpeng wrote: public class PublishController extends PublishAction implements Preparable { private static String message_url = "/post/message/"; private static String affair_url = "/post/affair/"; private static String business_url = "/post/business/"; private static String activity_url = "/post/activity/"; private static String announce_url = "/post/announce/"; private static String house_url = "/post/house/"; private static String case_url = "/post/case/"; private static String scenery_url = "/post/scenery/"; private static String poll_url = "/post/poll/"; if (category != null) { if (category.getCateId().equalsIgnoreCase(Category.MESSAGE)) { ServletActionContext.getResponse() .sendRedirect(ServletActionContext.getRequest().getContextPath() + message_url + "new"); } else if (category.getCateId().equalsIgnoreCase(Category.AFFAIR)) { ServletActionContext.getResponse() .sendRedirect(ServletActionContext.getRequest().getContextPath() + affair_url + "new"); > [...snip...] I'm not sure I understand the issue either, but man, isn't this what maps were made for?! Dave - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
Re:Re: Re: How to forward request in struts 2.1.6?
so many thanks. forgive my poor english. there are some words in this document: http://struts.apache.org/2.1.6/docs/rest-plugin.html Also, notice we aren't returning the usual "success" result code in either method. This allows us to use the special features of the Codebehind Plugin to intuitively select the result template to process when this resource is accessed with the .xhtml extension. In this case, we can provide a customized XHTML view of the resource by creating /orders-show.jsp and /orders-update.jsp for the respective methods. my code is like this: package com.xunan.sitexa.rest; import com.opensymphony.xwork2.Preparable; import com.xunan.sitexa.action.PublishAction; import com.xunan.sitexa.post.data.Category; import com.xunan.sitexa.post.service.CategoryService; import org.apache.struts2.ServletActionContext; import org.apache.struts2.rest.DefaultHttpHeaders; import org.apache.struts2.rest.HttpHeaders; import javax.servlet.ServletException; import java.io.IOException; /** * User: xnpeng * Date: 2009-4-21 * Time: 20:02:50 */ public class PublishController extends PublishAction implements Preparable { private static String message_url = "/post/message/"; private static String affair_url = "/post/affair/"; private static String business_url = "/post/business/"; private static String activity_url = "/post/activity/"; private static String announce_url = "/post/announce/"; private static String house_url = "/post/house/"; private static String case_url = "/post/case/"; private static String scenery_url = "/post/scenery/"; private static String poll_url = "/post/poll/"; public void prepare() { site = getHome(); } public HttpHeaders index() throws IOException { String cateId = ServletActionContext.getRequest().getParameter("cateId"); if (cateId != null && !cateId.equals("")) category = CategoryService.getCategory(cateId); if (category != null) { if (category.getCateId().equalsIgnoreCase(Category.MESSAGE)) { ServletActionContext.getResponse() .sendRedirect(ServletActionContext.getRequest().getContextPath() + message_url + "new"); } else if (category.getCateId().equalsIgnoreCase(Category.AFFAIR)) { ServletActionContext.getResponse() .sendRedirect(ServletActionContext.getRequest().getContextPath() + affair_url + "new"); } else if (category.getCateId().equalsIgnoreCase(Category.BUSINESS)) { ServletActionContext.getResponse() .sendRedirect(ServletActionContext.getRequest().getContextPath() + business_url + "new"); } else if (category.getCateId().equalsIgnoreCase(Category.ACTIVITY)) { ServletActionContext.getResponse() .sendRedirect(ServletActionContext.getRequest().getContextPath() + activity_url + "new"); } else if (category.getCateId().equalsIgnoreCase(Category.ANNOUNCE)) { ServletActionContext.getResponse() .sendRedirect(ServletActionContext.getRequest().getContextPath() + announce_url + "new"); } else if (category.getCateId().equalsIgnoreCase(Category.HOUSE)) { ServletActionContext.getResponse() .sendRedirect(ServletActionContext.getRequest().getContextPath() + house_url + "new"); } else if (category.getCateId().equalsIgnoreCase(Category.CASE)) { ServletActionContext.getResponse() .sendRedirect(ServletActionContext.getRequest().getContextPath() + case_url + "new"); } else if (category.getCateId().equalsIgnoreCase(Category.SCENERY)) { ServletActionContext.getResponse() .sendRedirect(ServletActionContext.getRequest().getContextPath() + scenery_url + "new"); } else if (category.getCateId().equalsIgnoreCase(Category.POLL)) { ServletActionContext.getResponse() .sendRedirect(ServletActionContext.getRequest().getContextPath() + poll_url + "new"); } } return new DefaultHttpHeaders(""); } public HttpHeaders show() throws IOException, ServletException { String cateId = ServletActionContext.getRequest().getParameter("cateId"); if (cateId != null && !cateId.equals("")) category = CategoryService.getCategory(cateId); String id = ServletActionContext.getRequest().getParameter("id"); if (category != null && id != null) { if (category.getCateId().equalsIgnoreCase(Category.MESSAGE)) { ServletActionContext.getServletContext().getRequestDispatcher(message_url + id + "/show") .forward(ServletActionContext.getRequest(), ServletActionContext.getResponse()); } else if (category.getCa
Re: Re: How to forward request in struts 2.1.6?
I'm not sure I understand your problem. Maybe you can give an example? I would be surprised if you couldn't handle this with regular Struts 2 results. http://struts.apache.org/2.1.6/docs/result-types.html http://struts.apache.org/2.1.6/docs/result-configuration.html http://struts.apache.org/2.1.6/docs/parameters-in-configuration-results.html Nils-H 2009/4/30 xnpeng : > thanks for your reply. > the result types cannot do my jobs in struts2+rest environment. in this > environment, the "success","error",... did not work, only "index","show" ,... > are the default result types. I can manage this. > > my situation is, I need to forward request to action conditionally,ie,depend > on "category" in action class. > > > > > 在2009-04-29,"Nils-Helge Garli Hegvik" 写道: >>Why do you need to do it manually with the request dispatcher? Can't >>you use any of the available result types? >> >>http://struts.apache.org/2.1.6/docs/result-types.html >> >>Nils-H >> >>2009/4/29 xnpeng : >>> from: >>> >>> ServletActionContext.getServletContext().getRequestDispatcher("/post/message/"+id).forward(ServletActionContext.getRequest(),ServletActionContext.getResponse()); >>> >>> I want to forward request to http://localhost:8080/post/message/3166, >>> >>> but it always throws out exception says requested resource not exist. >>> >>> when replace the string with "/index.jsp",it can work correctly. >>> >>> so, anyone who can help? I just want to forward request to an ACTION other >>> than jsp file. >>> >>> thanks. >> >>- >>To unsubscribe, e-mail: user-unsubscr...@struts.apache.org >>For additional commands, e-mail: user-h...@struts.apache.org >> > - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org
Re: How to forward request in struts 2.1.6?
Why do you need to do it manually with the request dispatcher? Can't you use any of the available result types? http://struts.apache.org/2.1.6/docs/result-types.html Nils-H 2009/4/29 xnpeng : > from: > > ServletActionContext.getServletContext().getRequestDispatcher("/post/message/"+id).forward(ServletActionContext.getRequest(),ServletActionContext.getResponse()); > > I want to forward request to http://localhost:8080/post/message/3166, > > but it always throws out exception says requested resource not exist. > > when replace the string with "/index.jsp",it can work correctly. > > so, anyone who can help? I just want to forward request to an ACTION other > than jsp file. > > thanks. - To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org