struts2简单的登陆界面,不能有效进行验证用户和密码,纠结了好久,求指导
struts.xml配置如下
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="default" namespace="/" extends="struts-default">
<action name="Login" class="com.LoginAction">
<result name="success">/welcome.jsp</result>
<result name="error">/error.jsp</result>
</action></package>
</struts>
web.xml配置如下
<?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.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping></web-app>
login.jsp如下
<%@ page language="java" contentType="text/html;charset=GBK"%>
<html>
<head>
<title>登陆页面</title>
</head>
<body>
<!--提交请求参数的表单-->
<form action="Login.action" method="post">
<table align="center">
<caption>用户登录</caption>
<tr>
<!--用户登录表单域-->
<td>用户名:<input type="text" name="useranme"/></td>
</tr>
<tr>
<!--用户表单域-->
<td>密 码:<input type="password" name="password"/></td>
</tr>
<tr align="center">
<td colspan="2"><input type="submit" value="登陆"/>
<input type="reset" value="重填"/></td>
</tr>
</table>
</form>
</body>
</html>
welcome.jsp如下:
<%@ page language="java" contentType="text/html;charset=GBK"%>
<html>
<head>
<title>成功页面</title>
<body>
您已经成功登陆
</body>
</html>
error.jsp如下
<%@ page language="java" contentType="text/html;charset=GBK"%>
<html>
<head>
<title>失败页面</title>
<body>
登陆不成功
</body>
</html>
LoginAction.java如下
package com;
public class LoginAction
{
private String username;
private String password;
public void setUsername(String username)
{
this.username=username;
}
public String getUsername()
{
return username;
}
public void setPassword(String password)
{
this.password=password;
}
public String getPassword()
{
return password;
}
public String execute() throws Exception
{
if(("ha".equals(username))&&("wei".equals(password)))
{
return "error";
}
return null