5.5 根据struts.xml里配置的内容,还需要一个welcome.jsp页面。编写welcome.jsp页面。代码如下:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'welcome.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
</head>
<body>
欢迎${username }!
</body>
</html>
经过上述步骤,登录实例已经编写完毕。启动tomcat,在网页地址栏里输入:http://localhost:8080/项目的名称/login.jsp,打开登录页面。如下所示:

输入用户名:haha,密码:hehe,点击登录,就来到了welcome.jsp页面。如下所示:

如果输入的用户名和密码不是haha和hehe,那么,就来到了login.jsp页面。
六、项目总结
简单的登录实例就完成了。这个例子里,还有一个需要注意的地方。LoginAction类继承了ActionSupport类,并且在execute方法的返回里,使用了SUCCESS和LOGIN变量。它们俩对应的值分别为:success、login(小写)。所以,在struts.xml里配置的result的name属性里,必须写为小写。要不然,会报"Could not find action or result"的错误。
