java - Struts 2 Hello word -
i'm new in struts 2 when run hello word example error http status 404 - there no action mapped namespace / , action name login. put jsp pages in wepapp/pages folder,how can solve that?
@resultpath(value="/") public class hellocontroller extends actionsupport{ /** * */ private static final long serialversionuid = 1l; private string name; public string getname() { return name; } public void setname(string name) { this.name = name; } @action(value="/login",results={@result(name="success",location="pages/login.jsp")}) public string execute()throws exception { return "success"; } }
web.xml
<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>/*</url-pattern> </filter-mapping>
and pom file
<dependencies> <dependency> <groupid>junit</groupid> <artifactid>junit</artifactid> <version>3.8.1</version> <scope>test</scope> </dependency> <dependency> <groupid>commons-logging</groupid> <artifactid>commons-logging</artifactid> <version>1.1.1</version> </dependency> <dependency> <groupid>org.apache.struts</groupid> <artifactid>struts2-core</artifactid> <version>2.1.8</version> </dependency> <dependency> <groupid>org.apache.struts</groupid> <artifactid>struts2-convention-plugin</artifactid> <version>2.1.8</version> </dependency> <dependency> <groupid>log4j</groupid> <artifactid>log4j</artifactid> <version>1.2.16</version> </dependency> <dependency> <groupid>javax</groupid> <artifactid>javaee-api</artifactid> <version>7.0</version> <scope>provided</scope> </dependency> </dependencies>
you should have call action name in url :
http://localhost:<your-port>/login.action
also change action name to:
@action(value="login" ....
Comments
Post a Comment