6.struts登陆页面的演示
//LoginAction.java
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.amaker.form.LoginForm;
public class LoginAction extends Action{
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
System.out.println("mapping.....");
// String username=request.getParameter("username");
// String password=request.getParameter("password");
//上面2行需要表单的处理
LoginForm login=(LoginForm)form;
String username=login.getUsername();
String password=login.getPassword(); if(username!=null&&username.equals("lily"))
{
// request.getRequestDispatcher("/Success.html").forward(request, response);
return mapping.findForward("success");
}else{
// request.getRequestDispatcher("/Failure.html").forward(request, response);
return mapping.findForward("failure");
}
//上面的return需要调转页面的处理
// return null;
}
}
//LoginForm.java
package com.amaker.form;
import org.apache.struts.action.ActionForm;
public class LoginForm extends ActionForm {
private String username;
private String password;
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;
}
}
3.配置struts-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd"> <struts-config>
<data-sources /> <form-beans>
<form-bean name="loginForm" type="com.amaker.form.LoginForm"></form-bean>
</form-beans>
//<form-beans>在.xml位置不能变不然会报错
//表格名字要与<action path="/login" //type="com.amaker.action.LoginAction" name="loginForm"> 相同
<global-exceptions />
<global-forwards /> <action-mappings>
<action path="/login" type="com.amaker.action.LoginAction" name="loginForm">
<forward name="success" path="/Success.html"></forward>
<forward name="failure" path="/Failure.html"></forward>
</action>
</action-mappings> <message-resources parameter="com.yourcompany.struts.ApplicationResources" />
</struts-config>
4.index.jsp
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
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> <body>
<form name="f1" id="f1" action="<%=path%>/login.do" method="post">
<table border="0">
<tr>
<td>Username:</td>
<td><input type="text" name="username" ></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="password" id="password"></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="Login"></td>
</tr>
</table>
</form>
</body>
</html>
5.Failure.html
<!DOCTYPE html>
<html>
<head>
<title>MyHtml.html</title> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8"> <!--<link rel="stylesheet" type="text/css" href="./styles.css">--> </head> <body> faliure!.....
</body>
</html>
6.Success.html
<!DOCTYPE html>
<html>
<head>
<title>MyHtml.html</title> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8"> <!--<link rel="stylesheet" type="text/css" href="./styles.css">--> </head> <body>
Success!........
</body>
</html>
6.struts登陆页面的演示的更多相关文章
- MUI APP防止登陆页面出现白屏
最近在用MUI开发APP,总体效果,在IOS上,是完美的,但是在低端的Android手机上,就会出现性能问题,我个人觉得最严重的是,就是首页,就是APP打开的第一个页面,在iOS上,由于性能高,所以, ...
- Struts2文件配置 登陆页面
Struts 版本号 struts-2.3.16.3 web.xml 配置 <?xml version=”1.0″ encoding=”UTF-8″?> <web-app versi ...
- 5、struct2使用登陆的时候重定向功能,如果没有登陆,重定向到登陆页面
1.实现这样一份功能,列如用户在进行某些操作的时候,如果没有登陆重定向到登陆页面 首先:我们创建一个功能操作页面,用户准备在该页面执行某些操作 在index.jsp中 <%@ page lang ...
- Springsecurity3.1.3配置多个登陆页面
需求:网站的前台和后台不同的url需要不同的登陆页面,不同的异常捕获方式. spring-security3.1以后的版本支持多个<http>标签,因此本文所采用的方式就是使用两个,实际上 ...
- web系统登陆页面增加验证码
传统登陆页面中包含两个输入项: • 用户名 • 密码有时为了防止机器人进行自动登陆操作,或者防止恶意用户进行用户信息扫描,需增加动态验证码功能.此时,登陆页面中包含了三个输入项: • 用户名 • 密码 ...
- Ajax 提交session实效跳转到完整的登陆页面
在spring security 中 Ajax提交时,session超时,局部加载登陆页面,为解决这个问题,重写ajax提交,返回的是modeview或者没有制定datatype时; 如果检测到加载到 ...
- js实现登陆页面的拖拽功能
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>登 ...
- iOS 本地加载html登陆页面
Html的代码 <!DOCTYPE html> <html lang="en"> <head> <meta charset="U ...
- 修改cas登陆页面-服务器端
原文地址:http://www.cnblogs.com/liveandevil/archive/2013/03/06/2946341.html 1.cas统一认证的登陆页面位于:cas目录/WEB-I ...
随机推荐
- shell 学习笔记
<Linux命令行与shell脚本编程大全>笔记 wkss 其他:http://www.cnblogs.com/pengdonglin137/p/3528303.html 一.基本命令 ...
- 《嵌入式Linux基础教程学习笔记一》
常用书目下载地址:http://www.cnblogs.com/pengdonglin137/p/3688029.html 第二章 1.进程上下文和中断上下文(Page20) 当应用程序执行系统调用, ...
- 关于禁止Android scrollView 因内容变化而自动滚动 android:descendantFocusability
出现这种情况是因为你让scrollview获得了焦点,所以它才会滚动.如果你百度了以后,你可能会发现有些博客会说让焦点停在固定的一个view中就可以了.这对于不存在刷新的页面确实是可以的,但是当你出现 ...
- UVa OJ 10071
Problem B Back to High School Physics Input: standard input Output: standard output A particle has i ...
- 标签云 - jqcloud 用法
html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF- ...
- cookie与session的区别与联系
cookie是什么? cookie是存在于客户端(浏览器). cookie的使用是由浏览器按照一定的原则在后台自动发送给服务器的.浏览器检查所有存储的cookie,如果某个cookie所声明的作用范 ...
- nc命令详解
NetCat,在网络工具中有“瑞士军刀”美誉,其有Windows和Linux的版本.因为它短小精悍(1.84版本也不过25k,旧版本或缩减版甚至更小).功能实用,被设计为一个简单.可靠的网络工具,可通 ...
- React Native教程 - 调用Web API
react-native官网Fetch介绍:https://facebook.github.io/react-native/docs/network.html#content react-native ...
- python字符串反转
最一般的想法就是将字符串先转换成列表,倒置列表,再将列表转换为字符串 s = 'Hello world' l = list(s) l.reverse() python ''.join(l) 而pyth ...
- ASP.Net 验证控件 CompareValidator
CompareValidator 作用就是比较两个输入框所输入的值是否一致,常用来作为验证输入密码和确认密码的业务. 属性 描述 Operator 比较操作符,可选值DataTypeCheck.Equ ...