Salve a tutti...
Sto provando ad eseguire la classica applicazione "Hello Nome" utilizzando struts2 con NetBeans 6.1 ma il tutto non funziona.(Da premettere che è la prima volta che utilizzo struts2).
Il progetto prevede una pagina index.jsp che tramite una form accetta il nome e poi premendo il tasto submit si deve attivare una Action che semplicemente preleva il nome dalla form e lo visualizza nella pagina di index con un saluto.
Il problema che esce fuori una volta inserito il nome e premuto il tasto submit è:
"HTTP Status 404 - There is no Action mapped for action name HelloWorld"
Il progetto è cosi strutturato:
src\java\tutorial\HelloWorld.java
src\java\tutorial\struts.xml
web\index.jsp
web\WEB-INF\web.xml
web\WEB-INF\lib\(le 5 librerie principali di struts 2)
Esiste qualche anima pia che puo indicarmi gli errori anche nel posizionamento del file struts.xml?
Vi ringrazio anticipatamante
--------------------------------------------------------------------
DOCUMENTO 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.FilterDispatch er</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>
--------------------------------------------------------------------
DOCUMENTO 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="tutorial" extends="struts-default">
<action name="HelloWorld" class = "tutorial.HelloWorld">
<result name="success">/index.jsp</result>
</action>
</package>
</struts>
-----------------------------------------------------------------------
-----------------------------------------------------------------------
PAGINA INDEX:JSP
-----------------------------------------------------------------------
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<!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=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h2>Inserisci il tuo nome</h2>
Struts 2 Message: <sroperty value="message" default="Guest." />
<s:form method="GET" action="tutorial/HelloWorld.action">
Enter your name:<s:textfield name="userName" />
<s:submit value="Submit" />
</s:form>
</body>
</html>
---------------------------------------------------------------------------
---------------------------------------------------------------------------
ACTION CLASS
---------------------------------------------------------------------------
package tutorial;
import com.opensymphony.xwork2.ActionSupport;
/**
*
* @author Amministratore
*/
public class HelloWorld extends ActionSupport{
private String userName;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
private String message;
public String getMessage() {
return message;
}
@Override
public String execute() {
message = "Hello, " + userName + ".";
return SUCCESS;
}
}

roperty value="message" default="Guest." />
Rispondi quotando