struts 登录实例
来源:互联网 发布:淘宝ceo和天猫ceo 编辑:程序博客网 时间:2024/05/16 11:56
web.xml 文件
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
登录页面代码
<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<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>
<script type="text/javascript">
function check(){
var username=document.getElementById("userName").value;
var password=document.getElementById("passWord").value;
if(username.length<=0){
alert("用户名不能为空");
return false;
}
if(password.length<=0){
alert("密码不能为空");
return false;
}
if(username.valueOf()==" "){
alert("用户名不能为空格")
return false;
}
if(password.valueOf()==" "){
alert("密码不能为空格")
return false;
}
from1.submit();
}
function checks(){
var username=document.getElementById("userName").value;
var password=document.getElementById("passWord").value;
if(username.length<=0){
alert("用户名不能为空");
return false;
}
if(password.length<=0){
alert("密码不能为空");
return false;
}
if(username.valueOf()==" "){
alert("用户名不能为空格")
return false;
}
if(password.valueOf()==" "){
alert("密码不能为空格")
return false;
}
alert("验证通过")
document.loginForm.submit();
}
</script>
<body>
<form name="from1" action="${pageContext.request.contextPath}/login.do?operate=login" method="post" >
username:<input type="text" name="userName"/><br>
password:<input type="text" name="passWord"><br>
<input type="button" name="button" value="tijiao" onclick="check()">
</form>
<html:form action="/login.do?operate=login" method="post">
username:<html:text property="userName" ></html:text>
password:<html:password property="passWord"></html:password>
<input type="button" name="button" value="提交" onclick="checks()">
</html:form>
</body>
</html>
action 代码
public ActionForward login(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
LoginForm userForm = (LoginForm) form;// TODO Auto-generated method stub
request.setAttribute("login", userForm);
System.out.println(userForm.getPassWord());
HttpSession session=request.getSession();
request.setAttribute("list", listadd());
session.setAttribute("users", userForm);
if(userForm.getUserName().equals("quwei")){
return mapping.findForward("ok");
}else{
return mapping.findForward("cuowu");
}
}
struts-config.xml
<action-mappings >
<action
attribute="loginForm"
name="loginForm"
parameter="operate"
path="/login"
scope="request"
type="com.cardvalue.view.action.LoginAction">
<set-property property="cancellable" value="true" />
<forward name="cuowu" path="/cuowu.jsp" />
<forward name="ok" path="/ok.jsp" />
</action>
- struts 登录实例
- struts入门实例--用户登录
- 【struts】使用struts完成登录实例
- struts+hibernate+spring简单登录实例
- struts+hibernate+spring简单登录实例
- struts+hibernate+spring简单登录实例
- 集成Struts+Spring+Hibernate 用户登录实例
- 通过struts框架完成登录的实例
- jquery,Struts,json 登录验证实例
- struts国际化实例---登录例子(中英文切换)
- Struts实例详解1--登录验证
- Struts从0开始1:普通的登录验证实例
- Struts 从零开始 一、普通的登录验证实例
- Struts中的拦截器——登录验证实例
- struts实例
- Struts实例
- Struts实例
- Struts 2.1.6 精简实例系列教程(6):重写用户登录模块(整合Jquery+JSON)
- PHP函数之CURL: 常见问题总结
- 十个方法,让你的线框原型更具沟通能力
- vs2010安装后sql server 2008的安装:
- php连接mysql数据库
- pthread相关介绍
- struts 登录实例
- 算法导论-25.1-最短路径与矩阵乘法
- linux中创建特殊文件mknod命令用法详解:
- kmp 朴素和升级 附 hdu 1711 3746 思想
- UItableViewCell的复用机制,原理解答
- doGet与doPost的区别
- J2SE基础夯实系列之List中的数据如何根据对象的某一个或多个字段排序引出Comparable和comparator的使用
- Real-Time Shadow Technique
- Selenium获取页面中树形结构的值,并存储到Vector中