Struts2学习之路_1_登录
来源:互联网 发布:前端开发优化问题 编辑:程序博客网 时间:2024/05/18 15:25
PS:因为这是第一次贴Struts2的代码,所以把Struts.xml和web.xml我都会贴出来,之后如果有大的改动我才会继续吧这个两个xml贴出来。
1、代码
1.1、web.xml
<?xml version="1.0" encoding="UTF-8"?><web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"><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> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list></web-app>
1.2、Struts.xml
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE struts PUBLIC"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN""http://struts.apache.org/dtds/struts-2.3.dtd"><struts> <!-- 原始的,可以用来参考 <constant name="struts.enable.DynamicMethodInvocation" value="false" /> <constant name="struts.devMode" value="true" /> <package name="default" namespace="/" extends="struts-default"> <default-action-ref name="index" /> <global-results> <result name="error">/error.jsp</result> </global-results> <global-exception-mappings> <exception-mapping exception="java.lang.Exception" result="error"/> </global-exception-mappings> <action name="index"> <result type="redirectAction"> <param name="actionName">HelloWorld</param> <param name="namespace">/example</param> </result> </action> </package> --> <constant name="struts.devMode" value="true" /> <!-- 如果value=true 开启开发模式,可以改完xml里面的东西就能自动刷新,不需要重新部署服务器 --> <package name="default" extends="struts-default"><action name="LoginAction_2014_4_28" class="com.god.action.LoginAction_2014_4_28"><result name="success">/2014_4_28_welcome_lx_01.jsp</result><result name="input">/2014_4_28_login_lx_01.jsp</result></action> </package> <include file="example.xml"/> <!-- Add packages here --></struts>
1.3、两个页面代码
1.3.1、2014_4_28_login_lx_01.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%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 '2014_4_28_login_lx_01.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> <center> <div> </div> <h3>这是一个简单的Struts 2应用</h3> <br/><hr/> <form action="LoginAction_2014_4_28.action" method="post"> 用户名:<input name="uname" type="text"/><br/> 密码:<input name="upasswd" type="text"/><br/> <input type="submit" value="提交"/> </form> </center> </body></html>
1.3.1、2014_4_28_welcome_lx_01.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%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 '2014_4_28_welcome_lx_01.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><center> <div> </div> <h3>一个简单的Struts 2应用</h3> <br/><hr/> ${uname}欢迎您! </center> </body></html>
1.4action代码
package com.god.action;import com.opensymphony.xwork2.ActionSupport;public class LoginAction_2014_4_28 extends ActionSupport {org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter d;private String uname;private String upasswd;public String getUname() {return uname;}public void setUname(String uname) {this.uname = uname;}public String getUpasswd() {return upasswd;}public void setUpasswd(String upasswd) {this.upasswd = upasswd;}public String execute(){// 类似于servlet的doGet和doPost方法if(uname.equals("fang")&&upasswd.equals("123")){return SUCCESS; //这两个return的东西要继承ActionSupport之后才能使用。}else{return INPUT;}}}
2、效果截图
2.1、2014_4_28_login_lx_01.jsp
2.2、2014_4_28_welcome_lx_01.jsp
0 0
- Struts2学习之路_1_登录
- Struts2学习之路_1_登录
- Struts2学习笔记之简单登录
- UML学习_1_模型
- struts2学习第一篇 环境配置 之 登录页面
- Struts2学习(九)—拦截器之登录权限
- php学习笔记_1_文件格式
- OC学习_1_一些常识
- Struts2学习-由“登录”开始
- VC++学习_1_学习资源与书籍
- J2EE系列之Struts2学习笔记(十三)--自定义拦截器示例之登录功能实现
- OpenGL开发&学习_1_环境配置
- Android学习笔记_1_拨打电话
- Java学习笔记_1_字符的读入
- C++ Primer 学习笔记_1_快速入门
- C++ Primer学习总结_1_开始
- C++ Primer学习总结_1_开始(续)
- 简明Python教程学习笔记_1_基本
- Linux学习之——Linux常用命令(三):文件搜索命令
- 谢娜为何炅策划惊喜生日会
- KMP模板
- 黑马程序员_7K面试题:十字路口的交通灯管理系统
- 对于世界而言,你可能是一个人,但是对于某人,你却是整个世界。
- Struts2学习之路_1_登录
- 说好的8点之前呢
- ArrayList Vector LinkedList 区别与用法
- 可用的通用makefile
- C++primer plus第六版课后编程题答案17.3
- Typedef的用法
- 字符设备和块设备的区别
- 凸包面积模板
- CATransform3D-Cube