Apostila FJ21 - Problema no Struts2

1 resposta
P

Galera, estou estudando a apostila da Caelum FJ21, cheguei agora na parte do Struts2.
O meu problema é que fazendo como a apostila manda a página web não é exibida.

Vou postar as classes:

formulario-tarefas.jsp

<title>Adicionar Tarefas</title>
</head>
<body>
<h3>Adicionar Tarefas</h3>
	<form action="adicionaTarefa" method="post">
		Descrição: <br />
		<textarea name="descricao" rows="5" cols="100"></textarea><br/>
		<input type="submit" value="Adicionar" />
	</form>
</body>
</html>

AdicionaTarefasAction.java

package br.com.caelum.tarefas.action;

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

import br.com.caelum.tarefas.dao.TarefaDAO;
import br.com.caelum.tarefas.modelo.Tarefa;

public class AdicionaTarefasAction {
	private Tarefa tarefa;
	
	@Action(value="adicionaTarefa", results = {
			@Result(name="ok", location="/tarefa-adicionada.jsp")
	})
	
	public String execute(){
		new TarefaDAO().adiciona(tarefa);
		return "ok";
	}
	
	public void setTarefa(Tarefa tarefa){
		this.tarefa = tarefa;
	}
	
	public Tarefa getTarefa(){
		return this.tarefa;
	}

}

tarefa-adicionada.jsp

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Tarefa adicionada</title>
</head>
<body>
<h3>Tarefa adicionada com sucesso!</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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
	version="3.0">
	<display-name>fj21-tarefas</display-name>
	<welcome-file-list>
		<welcome-file>index.html</welcome-file>
		<welcome-file>index.htm</welcome-file>
		<welcome-file>index.jsp</welcome-file>
		<welcome-file>default.html</welcome-file>
		<welcome-file>default.htm</welcome-file>
		<welcome-file>default.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>

Quando eu retiro do WEB.XML a parte do filtro a página abre normalmente.
A página formulario-tarefas.jsp está no raiz da pasta WebContent.

Se alguém puder ajudar...
Desde já agradeço.

1 Resposta

C

A tarefa-adicionada.jsp está na pasta content dentro de WEB-INF?

Se sim, tire a barra antes do nome da página no atributo location da anotação.

Se não poste aqui o log do erro.

Criado 18 de fevereiro de 2012
Ultima resposta 19 de fev. de 2012
Respostas 1
Participantes 2