hi,everyone
I meet an odd problem with struts2 annotation,Let me elaborate it first
import java.util.List;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang.StringUtils;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.apache.struts2.interceptor.validation.SkipValidation;
import org.springframework.beans.factory.annotation.Autowired;
import com.dbappsecurity.portal.model.PortalUser;
import com.dbappsecurity.portal.service.PortalUserService;
import com.opensymphony.xwork2.ActionSupport;
@Results({
@Result(name="input",location="main.jsp"),
@Result(name="list",location="list.jsp")
})
public class MainAction extends ActionSupport {
@Getter @Setter private PortalUser user;
@Autowired
private PortalUserService portalUserService;
public String execute() throws Exception {
return INPUT;
}
@Action("addUser")
public String addUser() throws Exception {
portalUserService.addUser(user);
return listUser();
}
@Action("listUser")
@SkipValidation
public String listUser() throws Exception {
List theUserList = portalUserService.getPortalUserList(null);
ServletActionContext.getRequest().setAttribute("userList",theUserList);
return "list";
}
@Action("modifyUser")
public String modifyUser() throws Exception {
List theUserList = portalUserService.getPortalUserList(null);
ServletActionContext.getRequest().setAttribute("userList",theUserList);
return "list";
}
this is the struts2 action class, I configure it correctly and type the url
http://domain/listUser it will list all users
http://domain/modifyUser it can modify the users
all things go well in tomcat with exploded class files
but when I build with the war file and deploy it into tomcat webapp folder,
the page report
there is no action name listUser
the difference between the two scenario is exploded class files and archived
class files that I compile and jar the action and other class files into it.
I was puzzled about this phenomenon
so any suggestions and advices will be very appreciated!