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 ...
随机推荐
- Golang学习 - io/ioutil 包
------------------------------------------------------------ // Discard 是一个 io.Writer 接口,调用它的 Write ...
- LeetCode30 Substring with Concatenation of All Words
题目: You are given a string, s, and a list of words, words, that are all of the same length. Find all ...
- MVC框架 - 异常处理
在ASP.NET中,错误处理是通过使用标准的尝试捕捉方法或使用应用程序事件.ASP.NET MVC附带内置支持,被称为异常过滤器功能异常处理.在这里我们要学习两种方法:一个是定义HandleError ...
- iOS中通知中心NSNotificationCenter应用总结
通知中心(NSNotificationCenter)实际是在程序内部提供了一种广播机制.把接收到的消息,根据内部的消息转发表,将消息转发给需要的对象.这句话其实已经很明显的告诉我们要如何使用通知了.第 ...
- spring mvc 重新定向到一个新的Url
在写项目的时候要求根据请求的参数的不同重新将请求分发,在查阅了spring mvc的一些资料无果后(想使用拦截器去做)就没办法使用重定向的方式去写了 /** * 通过访问API的方式分发请求 * * ...
- React Native学习-CameraRoll
react-native中CameraRoll模块提供了访问本地相册的功能. 在react版本为0.23.0的项目中,不支持Android,而且在iOS中使用CameraRoll还需要我们手动操作: ...
- [转]Web Services使用out参数
本文转自:http://www.cnblogs.com/zhaozhan/archive/2010/10/25/1860837.html Web Services使用out参数,在SOAP协议中会跟返 ...
- javascript学习笔记-1
说起来也挺丢人的,自己干了八年it,却从来没有好好从基础学习下javascript,曾经还认为和java有着多么大的联系. 真的很惭愧.今天开始有时间了,打算打打基础. JavaScript 有什么特 ...
- 【BUG】---ng-show/ng-hide修改成功但没有效果
问题:点击搜索,隐藏tab,出现搜索结果列表,调试也成功修改了分别元素的ng-hide就是没有效果 我的错误: <div ng-hide="{{isShow}}" class ...
- Fragment 总结
本博客代码地址 : -- 单一 Fragment 示例 : https://github.com/han1202012/Octopus-Fragement.git -- 可复用的 Fragment 示 ...