struts框架编写的用户登陆代码
2014-07-23 10:55
204 查看
1、index.jsp文件
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%><%@ taglib uri="/struts-tags" prefix="x"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'index.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">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<form action="login.action" method="post">
用户名:<input type="text" name="username"><br/>
密码:<input type="password" name="password"><br/>
<input type="submit" value="login">
</form>
</body>
</html>
2、web.xml文件
<?xml version="1.0" encoding="UTF-8"?><web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<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>
</web-app>
3、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>
<constant name="struts.i18n.encoding" value="UTF-8" />
<constant name="struts.ui.theme" value="simple"></constant>
<package name="login" extends="struts-default" namespace="/">
<action name="login" class="com.why.actions.LoginAction" method="f1">
<result name="success" type="dispatcher">
/wel.jsp
</result>
<result name="error" type="dispatcher">
/err.jsp
</result>
</action>
</package>
</struts>
4、LoginAction.java文件
package com.why.actions;import com.opensymphony.xwork2.ActionSupport;
public class LoginAction extends ActionSupport {
private static final long serialVersionUID = 5362742299006067572L;
private String username;
private String password;
public String f1()
{
if("why".equals(username)&&"123".equals(password)){
return "success";
}else{
return "error";
}
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
相关文章推荐
- 编写代码:ATM的登陆界面(用户验证、主菜单的选择) 查询-- 存款-- 取款-- 退出
- Nodejs使用coffeescript编写的用户注册/登陆代码(MySQL)
- ASP.net Logion用户登陆验证代码
- ASP.net Logion用户登陆验证代码
- asp.net下一个账号不允许多个用户同时在线,重复登陆的代码
- Shell命令编写——查看当前登陆用户的登录时间ac,last
- 使用过滤器过滤用户登陆代码
- C#编写的一个简单的登陆界面对话框的原代码
- Java Web 用户登陆示例代码
- php下使用curl模拟用户登陆的代码
- php用户验证登陆代码
- Javascript的用户指南--编写 JavaScript 代码
- 用户登陆模块的编写
- ASP.net Logion用户登陆验证代码
- 用户登陆代码(转)
- php下使用curl模拟用户登陆的代码
- ASP.net Logion用户登陆验证代码
- ASP.net Logion用户登陆验证代码
- 一个QQ多用户登陆的实例代码
- matches 正则表达式的使用 编写代码,验证手机号码,并告知用户是"189""158""130" 号段各自的运营公司, 如果号码长度有误,告诉用户手机号码 不存在。