Dae galera.. estou dando uma estudada no struts 2 e está aparecendo um problema.. estou fazendo um exemplo de login e tal.. ele funciona quase que corretamente.. a única coisa que não sei o porque é que a tag
<?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>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/jsp/*</url-pattern>
</filter-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
<?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>
<include file="struts-default.xml"/>
<package name="default" extends="struts-default">
<action name="login" class="br.gov.sc.alesc.action.LoginAction">
<result name="input">/jsp/login.jsp</result>
<result name="error">/jsp/login.jsp</result>
<result>/jsp/principal.jsp</result>
</action>
<!-- Add actions here -->
</package>
</struts>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="include/cssPrincipal.css" />
<title>..::Login::..</title>
</head>
<body>
<!-- jsp:include page="/jsp/errorValidation.jsp"/> -->
<!-- <div id="div_" align="center"> -->
<s:form action="login" method="POST" validate="true">
<tr>
<td colspan="2"><s:fielderror/></td>
</tr>
<tr>
<td colspan="2"><jsp:include page="/jsp/errorValidation.jsp"/></td>
</tr>
<s:textfield name="username" label="Login"/>
<s:password name="password" label="Senha"/>
<s:submit value="Login" align="center"/>
</s:form>
<!-- </div> -->
</body>
</html>
package br.gov.sc.alesc.action;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.validator.annotations.RequiredStringValidator;
import com.opensymphony.xwork2.validator.annotations.Validation;
/**
*
* @author Guitar
*/
@Validation
public class LoginAction extends ActionSupport {
private String username;
private String password;
public String execute() throws Exception {
if(!"admin".equals(getUsername()) || !"admin".equals(getPassword())) {
addActionError("Login ou Senha inválidos");
return ERROR;
} else {
return SUCCESS;
}
}
@RequiredStringValidator(message="Campo Login é Obrigatório")
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
@RequiredStringValidator(message="Campo Senha é Obrigatório")
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
Abraço!!