Olá Gente.
Pessoal, to jogando pro NetBeans o que aprendi de Struts2. Comecei do ZERO {Ola Mundo} pra não fica nada pra trás…hehe
Porém, fiz igualzinho a apostila de treinamento da Caelum(FJ-21) ensina no exercício.
Criar o pacote action(escolhi esse no caso)
Pegar os .jar’s do struts2 e definir na aplicação (não todos, pq segundo a apostila, não estamos usando o Spring)
e criar o mapeamento do FilterDispatcher do Struts2 no web.xml
e o menos importante creio eu que é a página olaMundoStruts.jsp que serve como camada de apresentação da aplicaçãozinha!
A seguir segue o que implementei:
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">
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.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>
CLASSE OlaMundoAction.java
package action;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.Result;
public class OlaMundoAction {
@Action(
value = "olaMundoStruts", results = {@Result(location = "/olaMundoStruts.jsp", name = "ok") }
)
public String execute(){
System.out.println("Execução da Lógica com Struts2!");
return "ok";
}
}
ADIANTANDO, O ERRO OCORRE ENTRE AS LINHAS 7 E 9 DA CLASSE olaMundoAction.java
Segue o erro gerado pelo NETBEANS
init:
deps-module-jar:
deps-ear-jar:
deps-jar:
Created dir: C:\Documents and Settings\THIAGO\Desktop\Struts2\build\web\WEB-INF\classes
Created dir: C:\Documents and Settings\THIAGO\Desktop\Struts2\build\web\META-INF
Copying 1 file to C:\Documents and Settings\THIAGO\Desktop\Struts2\build\web\META-INF
Copying 3 files to C:\Documents and Settings\THIAGO\Desktop\Struts2\build\web
library-inclusion-in-archive:
library-inclusion-in-manifest:
Created dir: C:\Documents and Settings\THIAGO\Desktop\Struts2\build\empty
Compiling 1 source file to C:\Documents and Settings\THIAGO\Desktop\Struts2\build\web\WEB-INF\classes
C:\Documents and Settings\THIAGO\Desktop\Struts2\src\java\action\OlaMundoAction.java:7: incompatible types
found : com.opensymphony.xwork2.Action
required: java.lang.annotation.Annotation
@Action(
1 error
C:\Documents and Settings\THIAGO\Desktop\Struts2\nbproject\build-impl.xml:543: The following error occurred while executing this line:
C:\Documents and Settings\THIAGO\Desktop\Struts2\nbproject\build-impl.xml:310: Compile failed; see the compiler error output for details.
FALHA NA CONSTRUÇÃO (tempo total: 0 segundos)
PRA NÃO FALTA NADA, A PÁGINA olaMundoStruts.jsp
<%--
Document : olaMundoStruts
Created on : 23/06/2011, 23:42:53
Author : THIAGO
--%>
<%@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">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Struts2</title>
</head>
<body>
<h2>Olá Mundo com Struts2!</h2>
</body>
</html>
Está faltando algo nesse código ou configurei alguma coisa errada na aplicação (Convenções, web.xml, enfim…hehe)?
Desde já agradeço a todos…Valeuuww