wood burning stoves 2.0*
The moose likes Struts and the fly likes Problem with namespace in Struts 2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Problem with namespace in Struts 2" Watch "Problem with namespace in Struts 2" New topic
Author

Problem with namespace in Struts 2

David Wimmer
Greenhorn

Joined: Jun 01, 2011
Posts: 13
Hello,

I tried to split my action definitions in different xml files with different namespaces.

When I am starting the project it is shown the Login site.

Now I click on submit (to force an error) the URL is this: http://localhost:8080/PeerTweetTemplate/login/Login.action

But when I am clicking then on Register the URL is this: http://localhost:8080/PeerTweetTemplate/login/RegisterPage.action and struts raises an error that the action is no mapping for the action.

My problem is, that struts 2 does not look in the default package for the action.


struts.xml



login.xml



register.xml

Oleg Vakil
Greenhorn

Joined: May 25, 2011
Posts: 5
Hello David,
I have exactly the same problem...
I am trying to start simplest my name example , basing on a lot of examples...
I dont want double your thread...
After near one day reading how simple and effective Struts2:-))) I have decided ask EXperts and saw your thread!

I will put my struts and web xmls..

web
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<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>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>

struts
<?xml version="1.0" encoding="UTF-8"?>
<struts>
<constant name="struts.devMode" value="true" />
<package name="Struts2App" namespace="/">
<action name = "sayhello" class="mypackage.Hello">
<result>/response.jsp</result>
</action>

</package>
</struts>

index.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib prefix = "s" uri="/struts-tags" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Hello World!</h1>
<s:form action="sayhello" >
<s:textfield name="name" label="Your name"/>
<s:submit/>
</s:form>
</body>
</html>

regards and be Lucky with Struts2!
Oleg Vakil
Greenhorn

Joined: May 25, 2011
Posts: 5
Ok
I just solved this problem for my task. I will put xmls, but more important was a location of struts.xml.
Curious, I was forced put it to sources!


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="struts-default">
<action name="sayhello" class="mypackage.Hello">
<result>/response.jsp</result>
</action>
</package>
</struts>
Although Netbeans complaining on mistakes in this xml....

web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<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>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>

my jspps:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib prefix = "s" uri="/struts-tags" %>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Hello World!</h1>

<s:form method="post" action="sayhello">
<s:textfield name="name" label="Your name"/>
<s:submit/>
</s:form>
</body>
</html>

and second one
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib prefix = "s" uri="/struts-tags" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Hello World!</h1>
I am <s:property value="message"/>
</body>
</html>

Be lucky

Also look at project's structure!



[Thumbnail for project.JPG]

David Wimmer
Greenhorn

Joined: Jun 01, 2011
Posts: 13
I did not want to bother a long time. So I've done all my actions in the default namespace and it works.



Oleg Vakil
Greenhorn

Joined: May 25, 2011
Posts: 5
David Wimmer wrote:I did not want to bother a long time. So I've done all my actions in the default namespace and it works.




Nice. But I think, problem is not connected to default namespace.
I tried default namespace too, it did not work.
best regards
Oleg
 
 
subject: Problem with namespace in Struts 2
 
Similar Threads
Struts 2 validation.xml not working
http 404 error in uploading the file
Issue configuring global results
Struts2 CannotRenderException
Error with Struts 2 and Tiles 2