文档下载 文档下载导航
设为首页 | 加入收藏
搜索 请输入内容:  
 导航当前位置: 文档下载 > 所有分类 > IT/计算机 > Struts2一个Action内包含多个请求处理方法的处理,method的使用方法,struts2中的路径问题,通配符映射
侵权投诉

Struts2一个Action内包含多个请求处理方法的处理,method的使用方法,struts2中的路径问题,通配符映射

Struts2一个Action内包含多个请求处理方法的处理,method的使用方法,struts2中的路径问题,通配符映射

if("test".equals(this.userName) && "test".equals(this.password)){

msg = "登录成功,欢迎" + this.userName;

//获取ActionContext实例,通过它来访问Servlet API

ActionContext context = ActionContext.getContext();

//看session中是否已经存放了用户名,如果存放了:说明已经登录了;

//否则说明是第一次登录成功

if(null != context.getSession().get("uName")){

msg = this.userName + ":你已经登录过了!!!";

}else{

context.getSession().put("uName", this.userName);

}



returnthis.SUCCESS;

}else{

msg = "登录失败,用户名或密码错";

returnthis.ERROR;

}

}


public String regist() throws Exception{

//将用户名,密码添加到数据库中

//...

msg = "注册成功。";

returnthis.SUCCESS;

}

}

2. struts.xml文件:没有什么变化,跟以前一样配置

<!DOCTYPE struts PUBLIC

"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"

"doc.guandang.net;

<struts>

<package name="my" extends="struts-default" namespace="/manage">

<!-- 定义处理请求URL为login.action的Action -->

<action name="userOpt" class="org.qiujy.web.struts2.action.LoginAction">

<!-- 定义处理结果字符串和资源之间的映射关系 -->

<result name="success">/success.jsp</result>

<result name="error">/error.jsp</result>

</action>

</package>

</struts>

3. 页面:

index.jsp

<%@ page language="java" pageEncoding="UTF-8"%>

<html>

<head>

<title>用户登录页面</title>

</head>

<body>

<h2>用户入口</h2>

<hr>

<form action="manage/userOpt!login.action" method="post">

<table border="1">

<tr>

<td>用户名:</td>

<td><input type="text" name="userName"/></td>

</tr>

<tr>

<td>密码:</td>

<td><input type="password" name="password"/></td>

</tr>

<tr>

<td colspan="2">

<input type="submit" value=" 确定 "/>

</td>

</tr>

</table>

</form>

</body>

</html>

regist.jsp

<%@ page language="java" pageEncoding="UTF-8"%>

<html>

<head>

<title>用户注册页面</title>

</head>

<body>

<h2>用户注册</h2>

<hr>

<form action="manage/userOpt!regist.action" method="post">

<table border="1">

<tr>

<td>用户名:</td>

<td><input type="text" name="userName"/></td>

</tr>

<tr>

<td>密码:</td>

<td><input type="password" name="password"/></td>

</tr>

<tr>

<td colspan="2">

<input type="submit" value=" 注册 "/>


上一页第4页

热门文档

相关文档

  • Struts2一个Action内包含多个请求处理方法的处理

    Struts2一个Action内包含多个请求处理方法的处理_IT/计算机_专业资料。Struts2...为 Action 配置 method 属性: 将 Action 类中的每一个处理方法都定义成一个...

  • Struts2一个Action内包含多个请求处理方法的处理

    Struts2 一个 Action 内包含多个请求处理方法的处理 Struts2 一个 Action 内包含多个请求处理方法的处理(三种方式) Struts1 提供了 DispatchAction,从而允许一个 ...

  • struts2动态方法调用详解

    Struts2 2010-07-11 Struts2一个Action内包含多个请求处理方法的处理(三种方式...动态方法调用: DMI:Dynamic Method Invocation 动态方法调用。 动态方法调用是指:...

  • 02_Struts中Action的使用

    的Action处理类 Action的动态方法调用一个Action内包含多个请求处理方法的处理 :...class="test.struts2.DMI.TestDMI" method="searchUsers"> <result>result.jsp...

  • Struts2的配置文件的详细说明

    1.1. 包配置: Struts2 框架中核心组件就是 Action、拦截器等,Struts2 框架...3. 一个 Action 内包含多个请求处理方法的处理 Struts1 提供了 DispatchAction,...

  • Struts2教程2:处理一个form多个submit

    请求参数名的格式为 action!method.action 注:由于 Struts2 只需要参数名,因此,参数值是什么都可以。 下面我就给出一个实例程序来演示如何处理有多个 submit 的 ...

  • Struts2_action笔记

    1) Struts2中最简单的要求就是你的Action类中要...此文件会自动包含到struts.xml中。 4) struts-...method: 指定处理这个请求的Action类的方法名。如果...

  • Struts2请求处理流程及源码分析

    一个请求在 Struts2 Struts2框架中的处理步骤: a) 客户端初始化一个指向 Servlet 容器的请求; b) 根据 Web.xml 配置,请求首先经过 ActionContextCleanUp 过滤...

  • 第二章 Struts2中的Action

    Struts2 中的Action 1 课程结构内容第一章:Struts2...Action: 业务逻辑控制器,负责处理单个特定请求 ? ...– 如果没有为action指定method,默认执行action中的 ...

  • struts2简答题

    2.与 struts1 对比,Struts2 的优点是什么? 对比,...在 struts.xml 中配 置 action 标签的 method ...将 调用 Action 里处理用户请求的处理方法;如果出现...

站点地图 | 文档上传 | 侵权投诉 | 手机版
本站所有资源均来自互联网,本站只负责收集和整理,均不承担任何法律责任,如有侵权等其它行为请联系我们.
文档下载 Copyright 2013 doc.guandang.net All Rights Reserved.  -  email