jsp页:
`
Struts.xml配置:
`<?xml version="1.0" encoding="GBK"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN"
"http://struts.apache.org/dtds/struts-2.1.7.dtd">
<struts>
<constant name="conststruts.devMode" value="true"/>
<!-- Struts2的所有Action都需位于package下 -->
<package name="first" extends="struts-default" namespace="/first">
<!-- 定义名为login的Action,其实现类为LoginAction类 -->
<action name="logindemo" class="com.struts.logindemo.loginDemoAction" method="execute">
<!-- 如果处理结果返回error,对应/error.jsp视图资源 -->
<result name="error">/error.jsp</result>
<!-- 如果处理结果返回success,对应/welcome.jsp视图资源 -->
<result name="success">/welcome.jsp</result>
</action>
</package>
</struts>
Java类:
``package com.struts.logindemo;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;
public class loginDemoAction extends ActionSupport{
String username ;
String userpassword ;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getUserpassword() {
return userpassword;
}
public void setUserpassword(String userpassword) {
this.userpassword = userpassword;
}
public String execute()
{
System.out.println("================================");
System.out.println("用户名是:"+username);
if(username.equals("lee"))
{
System.out.println("+++++++++++++++++++++++");
return SUCCESS;
}
else
return ERROR;
}
}
`