I’m trying to setup maven and struts 2 project in Eclipse, but I’m having problems. I have chosen to create simple HelloWorld example and afterwards add some other functionality, but I’m having problems.
I have ‘struts.xml’ path in project: src/main/resources/struts.xml
and inside it:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="default" namespace="/" extends="struts-default">
<action name="Login">
<result>/Pages/Login.jsp</result>
</action>
<action name="Index">
<result>/Pages/Index.jsp</result>
</action>
<action name="Welcome" class="com.contactweb.main.Contact">
<result name="SUCCESS">/Pages/Welcome.jsp</result>
</action>
</package>
</struts>
also I have web.xml with path src/main/web/WEB-INF/web.xml and content:
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>ContactWeb</display-name>
<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>
</web-app>
From commandline I use ‘mvn clean install’ and I get .war file to target folder, that .war file I’m going to deploy under Tomcat (also it deploys it successfully) but when I enter url I get error:
The requested resource (/ContactWeb/Pages/Login.jsp) is not available.
same error with different url-s only path is different (/ContactWeb/Login.jsp, /ContactWeb/Login.action etc.).
In my project I do have Login.jsp, Index.jsp and also Welcome.jsp. They are under: src/main/web/Pages
I have read somewhere that in struts2 I need to but .action extension to url, but it doesn’t work and also why in struts.xml is package name and namespace? what exactly needs to be there? I have read that is for page what it is going to display?
There’s not enough information to help yet, but enough wrong that it won’t fit into a comment.
Welcomeaction should almost certainly be the default,"success", unless you’re explicitly not using the S2 result names. Which IMO would be a bad idea.ContactWebcontext, then theLoginaction would be at/ContactWeb/Login.action(or whatever your suffix is, if you have one).devModeon, and (b) turn up logging to theDEBUGlevel while troubleshooting.src/main/webapp/Pagesdirectory? Note that it’s typical to hide JSPs from direct access by putting them underWEB-INF–I’d recommend you follow that practice.I’d recommend reading some of the S2 Guides; if you don’t know what the “package” and “namespace” attributes signify then IMO you should take a step back and try to understand some of the basics before randomly throwing code and configuration at a web container.