Struts 2 - tirando o .action da form

3 respostas
gustavobs

Não estou conseguindo rodar o codigo:

<%@taglib uri="/struts-tags" prefix="s"%>
<%@page contentType="text/html; charset=UTF-8"%>

<html>
	<head>
		<title>Meu primeiro formulário em Struts2</title>
	</head>
	
	<body>
		<h4> Escreva seu nome: </h4></br>
		<s:form action="helloName" method="post">
			<s:textfield name="nome" label="Seu nome"/>
			<s:submit/>
		</s:form>
	</body>
</html>

Se eu mudo p/ (funciona com o .action)

<%@taglib uri="/struts-tags" prefix="s"%>
<%@page contentType="text/html; charset=UTF-8"%>

<html>
	<head>
		<title>Meu primeiro formulário em Struts2</title>
	</head>
	
	<body>
		<h4> Escreva seu nome: </h4></br>
		<s:form action="helloName.action" method="post">
			<s:textfield name="nome" label="Seu nome"/>
			<s:submit/>
		</s:form>
	</body>
</html>

Pelo que já vi deveria rodar sem o .action, porém nao funciona! Alguem sabe pq?

3 Respostas

gustavobs

Ninguém ajudou, resolvi sozinho… ser cabeça dura é bom as vezes :wink:
Já alguem pode ter essa duvida vou escrever como deu certo:

A questão é que tem que declarar o jsp que contem o form no struts.xml tb.
Daí dá tudo certo :wink:

deivid

Fala galera estou com o mesmo problema! O Struts esta adicionando .action nas action. Como resolvo isso?

Obrigado

Meu struts.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
        "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
	<constant name="struts.objectFactory" value="spring"/>
	<constant name="struts.devMode" value="true"/>
	<package name="strutsapp" extends="struts-default">
		<action name="enviaContato" class="br.com.qualificare.action.EnviaContatoAction">
			<result name="input">contato.jsp</result>
			<result>contatoEnviado.jsp</result>
		</action>
	</package>
	
</struts>

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_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>qualificaresite</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>
  <!--  Declaração que vamos utilizar o filtro do struts2 -->
  <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>
	<!--  Fim da declaração que vamos utilizar o filtro do struts2 -->
	
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath:applicationContext.xml</param-value>
	</context-param>
	
	<listener>
		<listener-class>
		org.springframework.web.context.ContextLoaderListener	
		</listener-class>
	</listener>

</web-app>
deivid

Resolvido.

Quem quiser mudar a extensão do struts pode mudar no struts.properties alterando a propriedade

struts.action.extension

pode ser alterada no struts.xml tambem.

<constant name="struts.action.extension" value="suaextensao"/>
Criado 13 de julho de 2009
Ultima resposta 7 de set. de 2010
Respostas 3
Participantes 2