Struts 2 tutorial

1 resposta
R

Powww queria saber se alguem ai conhece da existencia de algum tutorial do struts2!!??

Abraço!!

XD

1 Resposta

Anderson_Leite

primeiro, baixa esse zip, e pega os jars do projeto struts.blanck-app

cria um jsp HelloWorld.jsp
<%@ taglib prefix="s" uri="/struts-tags" %>

<html>
    <head>
        <title>Hello World!</title>
    </head>
    <body>
        <h2><s:property value="message" /></h2>
    </body>
</html>
Cria uma classe java HelloWorld.java
package tutorial;
import com.opensymphony.xwork2.ActionSupport;
public class HelloWorld 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;
    }
}
Cria um arquivo xml struts.xml (Deve ficar no doretorio /src, pra ir pro WEB-INF/classes)
<!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>/HelloWorld.jsp</result>
        </action>
        <!-- Add your actions here -->
    </package>
</struts>

no seu web.xml coloca esse filtro

<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<filter-mapping>
<filter-name>applicationSessionFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

Seu helloworld com struts2 deve atender em http://localhost:8080/nomedasuaaplicacaoaqui/HelloWorld.action

fonte: http://struts.apache.org/2.0.14/docs/hello-world.html

Criado 17 de janeiro de 2009
Ultima resposta 18 de jan. de 2009
Respostas 1
Participantes 2