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=" 注册 "/>
Struts2一个Action内包含多个请求处理方法的处理_IT/计算机_专业资料。Struts2...为 Action 配置 method 属性: 将 Action 类中的每一个处理方法都定义成一个...
Struts2 一个 Action 内包含多个请求处理方法的处理 Struts2 一个 Action 内包含多个请求处理方法的处理(三种方式) Struts1 提供了 DispatchAction,从而允许一个 ...
Struts2 2010-07-11 Struts2一个Action内包含多个请求处理方法的处理(三种方式...动态方法调用: DMI:Dynamic Method Invocation 动态方法调用。 动态方法调用是指:...
的Action处理类 Action的动态方法调用一个Action内包含多个请求处理方法的处理 :...class="test.struts2.DMI.TestDMI" method="searchUsers"> <result>result.jsp...
1.1. 包配置: Struts2 框架中核心组件就是 Action、拦截器等,Struts2 框架...3. 一个 Action 内包含多个请求处理方法的处理 Struts1 提供了 DispatchAction,...
请求参数名的格式为 action!method.action 注:由于 Struts2 只需要参数名,因此,参数值是什么都可以。 下面我就给出一个实例程序来演示如何处理有多个 submit 的 ...
1) Struts2中最简单的要求就是你的Action类中要...此文件会自动包含到struts.xml中。 4) struts-...method: 指定处理这个请求的Action类的方法名。如果...
一个请求在 Struts2 Struts2框架中的处理步骤: a) 客户端初始化一个指向 Servlet 容器的请求; b) 根据 Web.xml 配置,请求首先经过 ActionContextCleanUp 过滤...
Struts2 中的Action 1 课程结构内容第一章:Struts2...Action: 业务逻辑控制器,负责处理单个特定请求 ? ...– 如果没有为action指定method,默认执行action中的 ...
2.与 struts1 对比,Struts2 的优点是什么? 对比,...在 struts.xml 中配 置 action 标签的 method ...将 调用 Action 里处理用户请求的处理方法;如果出现...
热门文档