0

This is the error messages:

WARNING: No configuration found for the specified action: 'welcome' in namespace: ''. Form action defaulting to 'action' attribute's literal value.

I have tried to put the struts under WEB-INF/classes already but it still doesn't work. I haven been stuck here a couple days now, please help.

struts.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 3.0//EN"
    "http://struts.apache.org/dtds/struts-2.5.dtd">
<struts>
<package name="default" namespace="/" extends="struts-default">
    <action name="login">
        <result>login.jsp</result>
    </action>
    <action name="welcome" class="com.struts3.LoginAction" method="execute">
        <result name="SUCCESS">welcome.jsp</result>
    </action>
</package>
</struts>

directory structure

login.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">
<%@ taglib uri="/struts-tags" prefix="s" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Login Page</title>
</head>
<body>
    <h3>Welcome to Struts 2</h3>
<s:form action="welcome">
    <s:textfield name="username" label="User Name"></s:textfield>
    <s:textfield name="password" label="Password" type="password"></s:textfield>
    <s:submit value="Login"></s:submit>
</s:form>   
</body>
</html>

welcome.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">
<%@ taglib uri="/struts-tags" prefix="s" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Welcome To Struts</title>
</head>
<body>
    <h3>Welcome <s:property value="username"/></h3>
</body>
</html>

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"
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>Basic Struts2</display-name>
<welcome-file-list>
    <welcome-file>/login.jsp</welcome-file>
</welcome-file-list>

<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 message error

Andy
  • 103
  • 1
  • 5

1 Answers1

1

The struts.xml configuration file must be on the root of the classpath, then on WEB-INF/classes, not in subpackages.

It should be put somewhere under src, and be copied to WEB-INF/classes at build-time by your favorite build-tool (Eclipse, Ant, Maven, ecc).

Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
  • so I put my **struts.xml** under `src` but it didn't cope the **struts.xml** to the `WEB-INF/classes` and I still get the same error. – Andy Dec 10 '15 at 14:56
  • Your build tool MUST copy the struts.xml from its original location (`src/whatever`, for example `src/main/resources`) to `WEB-INF/classes`. If it doesn't, this is another problem that you should fix before coming back to this one. When it will copy the struts.xml in `WEB-INF/classes`, it should work. – Andrea Ligios Dec 10 '15 at 15:33