Aí Galera,
Estou iniciando com Struts2, e estou tentanto fazer os tutoriais que existem no site da apache.
Só que estou tendo algumas dificuldades.
É mesmo necessário fazer o import do strutsblank.war? É que ao fazer o import, sao importados muitos ficheiros incluindo um exemplo que eles tem la.
Qdo fiz o import testei o exemplo do HelloWorld e rulou tudo, mas quando criei um projecto novo, fiz o import mas criei uma classe que se chama Ola, e já não funcionou, diz q não foi mapeada nenhuma acção.
Alguém me pode ajudar?
Vlw
//Graveyard
Cara não é complicado mais e so ate pegar o jeito, se vc veio do struts 1 algumas coisas mudaram vou te passar como deve ficar sua strutura…
struts.xml deve ficar na raiz do src(pacote de codigo fonte)
o conteudo deve ficar assim
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<!-- Configuration for the default package. -->
<include file="struts-default.xml"/>
<package name="default" extends="struts-default">
<action name="incluirUsuario" method="incluirUsuario" class="com.struts.action.Principal">
<result name="success">/usuario/usuario.jsp</result>
</action>
<action name="listarUsuario" method="listarUsuario" class="com.struts.action.Principal">
<result name="success">/usuario/usuario.jsp</result>
</action>
<action name="inicio" method="inicio" class="com.struts.action.Principal">
<result name="success" >/usuario/usuario.jsp</result>
</action>
</package>
</struts>
o teu web.xml deve ficar assim
<?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.html</welcome-file>
</welcome-file-list>
</web-app>
A tua action de extender um ActionSupport
public class Principal extends ActionSupport{
Qualquer duvida posta ai, falou
Boas,
Obrigado pela resposta, mas isso é o que eu tenho.
Eu vou postar aqui o meu cod. pra vc ver:
Estrutura dos ficheiros:
A estrutura dos files vao em anexo.
struts.xml
<!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="Ola" class="Ola">
<result>example/Ola.jsp</result>
</action>
<!-- Add your actions here -->
</package>
</struts>
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Struts Blank</display-name>
<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>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
index.html:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<META HTTP-EQUIV="Refresh" CONTENT="0;URL=example/Ola.action">
</head>
<body>
<p>Loading ...</p>
</body>
</html>
Ola.java
package tutorial;
import com.opensymphony.xwork2.ActionSupport;
public class Ola extends ActionSupport {
public static final String MESSAGE = "Struts is up and running ...";
public String execute() throws Exception {
setMessage(MESSAGE);
return SUCCESS;
}
private String message;
public void setMessage(String message){
this.message = message;
}
public String getMessage() {
return message;
}
}
Ola.jsp
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ page contentType="text/html; charset=UTF-8" %>
<html>
<head>
<title>Ola!</title>
</head>
<body>
<h2><s:property value="message" /></h2>
</body>
</html>
Ai está o meu codigo, mas não funciona.
Se vc puder dar uma olhada e detectar erros agradeço.
Vlw
//Graveyard
PS.: Eu não venho do Struts1, eu nc mexi com Struts.
![](https://www.guj.com.br/uploads/default/original/3X/5/0/50aa9a9672eabe876c9c9452d047da089f05ce09.jpg)
faz um teste para dar uma olhada
no struts.xml faz assim
<!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="Ola" class="Ola">
<result name="success">example/Ola.jsp</result>
</action>
<!-- Add your actions here -->
</package>
</struts>
acho que é isso
Boas,
Mais uma vez obrigado pela dica, mas não funciona.
O erro que dá é o 404.
HTTP Status 404 - There is no Action mapped for action name Ola.
message: There is no Action mapped for action name Ola.
description: The requested resource (There is no Action mapped for action name Ola.) is not available.
Não sei mais que fazer, por aquilo que tenho visto isto não é normal.
Tem mais alguma ideia?
Vlw
//Graveyard
da uma olhada nesse exemplo que ira te ajudar muito, qualquer duvida posta ai, falou…
http://www.4shared.com/file/67814079/3afea795/Struts2.html