1

I have created a web dynamic project Struts2Starter and for Target runtime, web container is Apache Tomcat 7.

When I run this project, it gives an error:

The requested resource(/Struts2Starter/) is not available

Here's the path:

Project Explorer

Webb folder elements/files/contents deployed and in Deployed Resources folder:

Webb folder elements/files/contents deployed and in Deployed Resources folder

Code snippets:

struts.xml:

<?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" extends="default">
<action name="getTutorial" class="TutorialAction">
<result name="success">/success.jsp</result>
<result name="failure">/error.jsp</result>

</action>
</package>


</struts>

web.xml:

 <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
      <display-name>Struts2Starter</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>

error.jsp:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
Error Page!
</body>
</html>

success.jsp:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
Success Page!
</body>
</html>

However, when I am running other web projects they run fine. I had given welcome file in web.xml. I removed it later because I did not need it.

I tried running:

http://localhost:8083/Struts2Starter/
http://localhost:8083/Struts2Starter/TutorialAction
http://localhost:8083/Struts2Starter/TutorialAction.action

Same error for all as compiler does not find project available.

Project is built. Port is 8083 and not 8080, as 8080 is already used for some service. However, as i mentioned earlier, other web projects are running fine with Apache 7, using 8083. In Deployment Assembly for project, i had mapped my user Library "Struts2" (shown in project explorer image above) to Deploy Path "WEB-INF/lib".

I am not able to figure out why project is not running, any suggestions? I have referred other threads with similar issue, but most of them are for servlets and i am not doing any servlet mapping and instead using filter.

Error Snapshot:

Error Snapshot

Roman C
  • 49,761
  • 33
  • 66
  • 176
  • is folder `webb` in your deployment assembly? – Yogesh Jul 21 '14 at 13:04
  • @Yogi yes, everything in my webb folder is in Deployed Resorces folder. I will add a snapshot of its project structure in main thread. –  Jul 22 '14 at 04:30
  • i tried changing struts.xml DOCTYPE to: It still doesnt work. –  Jul 22 '14 at 09:26

2 Answers2

0

Try following in your struts configuration

<?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" extends="default" namespace="/">

        <action name=""> <!-- or you can include index.jsp file in web.xml -->
            <result>/index.jsp</result>
        </action>

        <action name="getTutorial" class="TutorialAction">
            <result name="success">/success.jsp</result>
            <result name="failure">/error.jsp</result>
        </action>

    </package>
</struts>

If you don't provide namespace The default namespace is "" an empty string. Here is documentation

Yogesh
  • 4,546
  • 2
  • 32
  • 41
  • Hi Yogi, i tried what you suggested. Created index.jsp too and used as shown above. gave namespace. yet its not working..any more suggestions? Thankyou for your time. –  Jul 21 '14 at 11:33
0

You have used

http://localhost:8083/Struts2Starter/
http://localhost:8083/Struts2Starter/TutorialAction
http://localhost:8083/Struts2Starter/TutorialAction.action

but neither of them map to the action. struts.xml should be modified and changed for the correct DTD.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">

<struts>
 <package name="default" extends="struts-default">
  <action name="getTutorial" class="TutorialAction">
    <result name="success">/success.jsp</result>
    <result name="failure">/error.jsp</result>
  </action>
</package>

Try this urls

http://localhost:8083/Struts2Starter/getTutorial
http://localhost:8083/Struts2Starter/getTutorial.action

Also download all necessary jars to the lib folder of your application. For example commons-lang3-3.3.2.jar.

Roman C
  • 49,761
  • 33
  • 66
  • 176
  • Hi @Roman C Yes, you are right, my URL itself was wrong. I added all required JARs to lib folder. Then gave correct URLs. yet it is not working. Any suggestions on where i cud be missing the key point.? Thankyou. –  Jul 21 '14 at 12:11
  • Could you execute the action? Also why didn't you configure your project's web root folder? What is this `webb.xml` your last edit? – Roman C Jul 21 '14 at 12:56
  • Hi @Roman C webb is content directory folder, where i store all web files(core business logic in core java does not go here). On the other hand, web.xml is for configuration. In a normal web dynamic project ths is expected to map servlets with JSPs or URLs, but since this is struts project, i dont need servlets and this file is instaed used for filters. I have added a snapshot in main thread which shows that webb folder files are in Deployed resources. (2nd project explorer image in main thread). Thankyou. –  Jul 22 '14 at 10:41
  • Until the files are deployed on the server this folder is useless, and if you putting your java files make sure they under web-if. How you configure your project in eclipse is meaningless to the server which operated on web deployment descriptor that has a defined name. You also can't run your project without it unless you are using resent servlets technology. When you project is deployed you can access an action by specifying url that mapped to the action using struts configuration. Improper mapping can result in 404 status code, which is produced by default servlet used by tomcat to handle. – Roman C Jul 22 '14 at 10:58
  • Hi @Roman C, thankyou for taking time. i dont know how to explicitly deploy my files on server. I have created project and its file in the exact manner i had created any other running web application.How do go explicit about this? And why should i put my core java files in WEB/INF folder. While calling i hope i am being accurate. Thankyou much for your time and patience. –  Jul 22 '14 at 11:30
  • i have downloaded and used struts-2.3.16.3 JAR files –  Jul 22 '14 at 11:38
  • _i dont know how to explicitly deploy my files on server_ this is offtop, I have nothing say about this. If you have another question you can use link on this page do do that. Cheers. – Roman C Jul 22 '14 at 12:25
  • can someone precisely tell me how to do what i am missing step by step? If there was problem with deployment, i have done other web projects just the exact way and they work fine. Since this is struts project, the difference is using filter mapping in web.xml and then adding package and action in struts.xml. Path to each folder and code is in original thread. Kindly tell me step by step on what to do at the point i am getting stuck and not in general. i dont want to craete dependency on pro IDEs and want to use free ones like eclipse juno which i am alraedy using. Thanks. –  Jul 23 '14 at 06:44