Iniciando em Struts2

Estou estudando a apostila fj21 da caelum. Estou começando a parte de struts 2 e nem consegui rodar aquele hello world ainda. Importei todos jars como explica a apostila, o xml tá igual lá e talz segue. Se puderem me explicar como proceder, com um passo-a-passao “mais detalhado”, pois estou com dificuldade.

Agradeço desde já!

XML

[code]<?xml version="1.0" encoding="UTF-8"?>

fj21-tarefas

index.html
index.htm
index.jsp
default.html
default.htm
default.jsp

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

[/code]

Action OlaMundoAction

[code]package br.com.caelum.tarefas.action;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;

public class OlaMundoAction {

@Action(value = "olaMundoStruts", results = { 
		@Result(location = "/WEB-INF//olaMundoStruts.jsp", name = "ok") })
		
public String execute() {
	System.out.println("Executando a lógica com Struts2");
	return "ok";
}

}[/code]

Olha só o que tá dando no log do tomcat:

29/10/2010 14:00:39 org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Arquivos de programas\Java\jre6\bin;.;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:/Arquivos de programas/Java/jre6/bin/client;C:/Arquivos de programas/Java/jre6/bin;C:/Arquivos de programas/Java/jre6/lib/i386;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Arquivos de programas\TortoiseSVN\bin;C:\Arquivos de programas\Java\jdk1.6.0_12\bin;C:\eclipse\plugins\org.apache.ant_1.7.0.v200803061910\bin;C:\Arquivos de programas\MySQL\MySQL Server 5.1\bin
29/10/2010 14:00:39 org.apache.tomcat.util.digester.SetPropertiesRule begin
AVISO: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property ‘source’ to ‘org.eclipse.jst.jee.server:fj21-tarefas’ did not find a matching property.
29/10/2010 14:00:39 org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
29/10/2010 14:00:39 org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 1001 ms
29/10/2010 14:00:39 org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
29/10/2010 14:00:39 org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.29
29/10/2010 14:00:40 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
INFO: Parsing configuration file [struts-default.xml]
29/10/2010 14:00:40 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
INFO: Parsing configuration file [struts-plugin.xml]
29/10/2010 14:00:40 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
INFO: Unable to locate configuration files of the name struts.xml, skipping
29/10/2010 14:00:40 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
INFO: Parsing configuration file [struts.xml]
29/10/2010 14:00:41 com.opensymphony.xwork2.util.logging.commons.CommonsLogger error
GRAVE: Dispatcher initialization failed
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at com.opensymphony.xwork2.inject.ContainerImpl$MethodInjector.inject(ContainerImpl.java:295)
at com.opensymphony.xwork2.inject.ContainerImpl$ConstructorInjector.construct(ContainerImpl.java:431)
at com.opensymphony.xwork2.inject.ContainerBuilder$5.create(ContainerBuilder.java:207)
at com.opensymphony.xwork2.inject.Scope$2$1.create(Scope.java:51)
at com.opensymphony.xwork2.inject.ContainerBuilder$3.create(ContainerBuilder.java:93)
at com.opensymphony.xwork2.inject.ContainerBuilder$7.call(ContainerBuilder.java:487)
at com.opensymphony.xwork2.inject.ContainerBuilder$7.call(ContainerBuilder.java:484)
at com.opensymphony.xwork2.inject.ContainerImpl.callInContext(ContainerImpl.java:574)
at com.opensymphony.xwork2.inject.ContainerBuilder.create(ContainerBuilder.java:484)
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.createBootstrapContainer(DefaultConfiguration.java:252)
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:193)
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:66)
at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:371)
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:415)
at org.apache.struts2.dispatcher.ng.InitOperations.initDispatcher(InitOperations.java:69)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.init(StrutsPrepareAndExecuteFilter.java:51)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:295)
at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:422)
at org.apache.catalina.core.ApplicationFilterConfig.(ApplicationFilterConfig.java:115)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4001)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4651)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:445)
at org.apache.catalina.core.StandardService.start(StandardService.java:519)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:581)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.opensymphony.xwork2.inject.ContainerImpl$MethodInjector.inject(ContainerImpl.java:293)
… 33 more
Caused by: java.lang.ExceptionInInitializerError
at com.opensymphony.xwork2.ognl.OgnlValueStackFactory.setContainer(OgnlValueStackFactory.java:85)
… 38 more
Caused by: java.lang.IllegalArgumentException: Javassist library is missing in classpath! Please add missed dependency!
at ognl.OgnlRuntime.(OgnlRuntime.java:165)
… 39 more
Caused by: java.lang.ClassNotFoundException: javassist.ClassPool
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1645)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1491)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at ognl.OgnlRuntime.(OgnlRuntime.java:162)
… 39 more
29/10/2010 14:00:41 org.apache.catalina.core.StandardContext filterStart
GRAVE: Exception starting filter struts2
java.lang.reflect.InvocationTargetException - Class: com.opensymphony.xwork2.inject.ContainerImpl$MethodInjector
File: ContainerImpl.java
Method: inject
Line: 295 - com/opensymphony/xwork2/inject/ContainerImpl.java:295:-1
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:428 )
at org.apache.struts2.dispatcher.ng.InitOperations.initDispatcher(InitOperations.java:69)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.init(StrutsPrepareAndExecuteFilter.java:51)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:295)
at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:422)
at org.apache.catalina.core.ApplicationFilterConfig.(ApplicationFilterConfig.java:115)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4001)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4651)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:445)
at org.apache.catalina.core.StandardService.start(StandardService.java:519)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:581)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at com.opensymphony.xwork2.inject.ContainerImpl$MethodInjector.inject(ContainerImpl.java:295)
at com.opensymphony.xwork2.inject.ContainerImpl$ConstructorInjector.construct(ContainerImpl.java:431)
at com.opensymphony.xwork2.inject.ContainerBuilder$5.create(ContainerBuilder.java:207)
at com.opensymphony.xwork2.inject.Scope$2$1.create(Scope.java:51)
at com.opensymphony.xwork2.inject.ContainerBuilder$3.create(ContainerBuilder.java:93)
at com.opensymphony.xwork2.inject.ContainerBuilder$7.call(ContainerBuilder.java:487)
at com.opensymphony.xwork2.inject.ContainerBuilder$7.call(ContainerBuilder.java:484)
at com.opensymphony.xwork2.inject.ContainerImpl.callInContext(ContainerImpl.java:574)
at com.opensymphony.xwork2.inject.ContainerBuilder.create(ContainerBuilder.java:484)
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.createBootstrapContainer(DefaultConfiguration.java:252)
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:193)
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:66)
at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:371)
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:415)
… 20 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.opensymphony.xwork2.inject.ContainerImpl$MethodInjector.inject(ContainerImpl.java:293)
… 33 more
Caused by: java.lang.ExceptionInInitializerError
at com.opensymphony.xwork2.ognl.OgnlValueStackFactory.setContainer(OgnlValueStackFactory.java:85)
… 38 more
Caused by: java.lang.IllegalArgumentException: Javassist library is missing in classpath! Please add missed dependency!
at ognl.OgnlRuntime.(OgnlRuntime.java:165)
… 39 more
Caused by: java.lang.ClassNotFoundException: javassist.ClassPool
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1645)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1491)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at ognl.OgnlRuntime.(OgnlRuntime.java:162)
… 39 more
29/10/2010 14:00:41 org.apache.catalina.core.StandardContext start
GRAVE: Error filterStart
29/10/2010 14:00:41 org.apache.catalina.core.StandardContext start
GRAVE: Context [/fj21-tarefas] startup failed due to previous errors
29/10/2010 14:00:41 org.apache.catalina.loader.WebappClassLoader clearThreadLocalMap
GRAVE: The web application [/fj21-tarefas] created a ThreadLocal with key of type [null] (value [com.opensymphony.xwork2.inject.ContainerImpl$10@8ceeea]) and a value of type [java.lang.Object[]] (value [[Ljava.lang.Object;@995a79]) but failed to remove it when the web application was stopped. This is very likely to create a memory leak.

Alguém pode ajudar aí ?

Obrigado!

E aí galera consegui resolver, tava faltando algumas libs, vou postar aqui o que eu fiz talvez alguém tenha futuramente o mesmo problema:

commons-fileupload-X.X.X.jar
commons-io-X.X.X.jar
commons-logging-X.X.X.jar
commons-logging-api.X.X.jar
freemarker-X.X.X.jar
ognl-X.X.X.jar
struts2-core-X.X.X.X.jar
xwork-core-X.X.X.jar
javassist-3.7.ga.jar (new for Struts versions 2.2.1 and higher)
log4j-1.2.14.jar
struts2-convention-plugin-x.x.x

e crie os arquivos struts.xml e log4j.xml na pasta src

log4j.xml

[code]<?xml version="1.0" encoding="UTF-8" ?>

<log4j:configuration xmlns:log4j=“http://jakarta.apache.org/log4j/”>

<appender name="STDOUT" class="org.apache.log4j.ConsoleAppender">
	<layout class="org.apache.log4j.PatternLayout">
		<param name="ConversionPattern" value="%d %-5p %c.%M:%L - %m%n" />
	</layout>
</appender>

<!-- specify the logging level for loggers from other libraries -->
<logger name="com.opensymphony">
	<level value="DEBUG" />
</logger>

<logger name="org.apache.struts2">
	<level value="DEBUG" />
</logger>

<!-- for all other loggers log only debug and above log messages -->
<root>
	<priority value="INFO" />
	<appender-ref ref="STDOUT" />
</root>

</log4j:configuration>
[/code]

struts.xml

[code]<?xml version="1.0" encoding="UTF-8"?>

<constant name="struts.devMode" value="true" />

<package name="basicstruts2" extends="struts-default">

	<action name="index">
		<result>/index.jsp</result>
	</action>

</package>
[/code]

OlaMundoAction.java

[code]package br.com.caelum.tarefas.action;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;

public class OlaMundoAction {

@Action(value = "olaMundoStruts", results = { 
		@Result(location = "/olaMundoStruts.jsp", name = "ok") }) //Corrigido aqui também
		
public String execute() {
	System.out.println("Executando a lógica com Struts2");
	return "ok";
}

}[/code]

Eu fiz isso… mais não deu certo…
Se poder ajudar–> http://www.guj.com.br/java/255861-struts-2-problema-na-atividade-116-da-apostila-da-caelum#1331929

Olha não precisa criar o struts.xml , nem o log …

Apenas muda essa linha :

    @Result(location = "/olaMundoStruts.jsp", name = "ok") })

Tira a “/”.

@Result(location = “olaMundoStruts.jsp”, name = “ok”) })

Testa e posta o resultado !

Continua aparecendo isso…

HTTP Status 404 - /fj21-tarefas/olaMundoStruts

type Status report

message /fj21-tarefas/olaMundoStruts

description The requested resource (/fj21-tarefas/olaMundoStruts) is not available.
Apache Tomcat/6.0.33

Quando eu coloco o filtro da erro. Tipo seu eu colocar http://localhost:8080/fj21-tarefas/ com o filtro no web.xml da erro(não aparece o index) e se eu colocar sem o filtro da tudo ok(aparece o index)…
Será que o poblrma não tá no filtro???
Eu coloquei o projeto no SkyDrive se alguem poder da uma olhada… vlw!!
https://skydrive.live.com/redir.aspx?cid=d6b369f16...7e3&resid=D6B369F16014E7E3!126

Bom , olhando seu projeto , achei o erro.

Está faltando jars.

asm-3.1.jar
asm-commons-3.1.jar

E é claro , que também está faltando algum jar de conexão com o banco de dados .

Caso você queira mexer com banco também , coloque o jar dele também .

E não esqueça de ADD no build path!

Abraço.

[quote=JoaoMarques]Bom , olhando seu projeto , achei o erro.

Está faltando jars.

asm-3.1.jar
asm-commons-3.1.jar

E é claro , que também está faltando algum jar de conexão com o banco de dados .

Caso você queira mexer com banco também , coloque o jar dele também .

E não esqueça de ADD no build path!

Abraço.[/quote]

Eu fiz isso e continua dando erro…
HTTP Status 404 - /fj21-tarefas/WEB-INF/content/olaMundoStruts.jsp

type Status report

message /fj21-tarefas/WEB-INF/content/olaMundoStruts.jsp

description The requested resource (/fj21-tarefas/WEB-INF/content/olaMundoStruts.jsp) is not available.
Apache Tomcat/6.0.33

Mais olha essa linha:

description The requested resource (/fj21-tarefas/WEB-INF/content/olaMundoStruts.jsp) is not available.

Ele ta entrando dentro do WEB-INF isso ta certo?? Meu .jsp está dentro do WebContent… e fora do WEB-INF