Search code examples
javaeclipsejakarta-eestruts2struts-config

Struts.xml package namespace in eclipse


I'm trying to setup an apache tomcat server with a struts application. Problem was the project's directory structure was poorly mapped out. I've updated it and running into a problem when I try to start my server. My folder structure is as follows.

enter image description here

The main thing I changed was moving all of the jsp files into a separate folder, they were originally just directly in the Web Content folder. My problem is now I THOUGHT the only thing I needed to change was the struts.xml's package default namespace (the only one they made) to "/jsp" thinking the "/" would point to the web content folder and adding jsp would hit the right folder. However it doesn't seem to be the case. I get an error that "There is no Action mapped for namespace "/" and action name mainDashboardHome." (tried cleaning server, clearing FF cache, and restarting eclipse), like it didn't even see that I changed the package's namespace. My web.xml is super basic filtering all url patterns to struts2. The only thing I can think of is the Welcom-file-list : Welcome.jsp's redirect needs to change... code below. Not sure what to change it to.

<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
</head>
<body>
  <% response.sendRedirect("mainDashboardHome.action"); %>
</body>
</html>

Also the start of my struts.xml package definition with dashboard action (located in the SRC folder):

<struts>
...  
<package name="default" extends="struts-default" namespace="/jsp">  
...  
<action name="mainDashboardHome" method="mainDashBoard"
        class="mainDashboard.Action.ApplicationRouteAction">
        <result name="success">test.jsp</result>
        <result name="error">Login.jsp</result>

    </action>

Solution

  • here is the theory: namespace and action name DON'T have to correspond to your action or jsp file location (although you can do that yourself for convenience, i do that :D :D :D). namespace and action name mainly affects how client will see its url. the action file and jsp file are to be specified in your struts.xml

    in your case, the user will see mainDashboardHome's url as .../jsp/mainDashboardHome.action

    since you said you moved your jsps to special folder, and your result tag content doesn't show any folder, i think your jsp file location setting (<result name="success/error">wherever_your_jsp_is.jsp</result>) must be changed

    so, i think here are the steps for your troubleshooting: 1. change the namespace into "/" (not strictly necessary, though. i depends on how you want the url to be) 2. change the jsp locations inside the result tags to the one where you stored your jsp files

    and as a side note, you don't need to put response.sendRedirect("mainDashboardHome.action"); inside your jsp. you can do this instead in your struts.xml:

    <action blablabla>
       <result name="anotherblablabla" type="redirectAction">
            <param name="namespace">/</param>
            <param name="actionName">mainDashboardHome</param>
       </result>
    </action>