struts的动态方法调用
来源:互联网 发布:用excel查找重复数据 编辑:程序博客网 时间:2024/05/02 19:04
1.首先在struts.xml文件中设置支持动态方法的调用
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd"><struts>
<!--动态方法调用设置为true支持-->
<span style="white-space:pre"></span><constant name="struts.enable.DynamicMethodInvocation" value="true">
<span style="white-space:pre"></span><package name="my" extends="struts-default" namespace="/"><span style="white-space:pre"></span><action name="test" class="com.itany.action.UserAction"><span style="white-space:pre"></span><result>/success.jsp</result><span style="white-space:pre"></span><result name="error">/error.jsp</result><span style="white-space:pre"></span></action><span style="white-space:pre"></span><span style="white-space:pre"></span><action name="reg" class="com.itany.action.UserAction"><span style="white-space:pre"></span><result>/registesuccess.jsp</result><span style="white-space:pre"></span></action><span style="white-space:pre"></span></package>
<pre name="code" class="html"></struts>
前台页面jsp代码:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%@taglib uri="/struts-tags" prefix="s" %><%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">--><script type="text/javascript">function changeUrl(){tagform=document.forms[0]; //获取第一个form保单tagform.action="reg!registe.action?msg=qwe";tagform.submit();}</script> </head> <body> <!-- 感叹号说明调用的是哪个方法,格式是actionName!methodName.action --> <form action="test!login.action" method="post"> username:<input type="text" name="username" /><br/> password:<input type="password" name="password"/><br/> <input type="submit" value="submit"/> <input type="button" value="registe" onclick="changeUrl()"/> </form> </body></html>
package com.itany.action;import javax.servlet.http.HttpServletRequest;import org.apache.struts2.ServletActionContext;import com.opensymphony.xwork2.ActionSupport;public class UserAction extends ActionSupport {private String msg;public String getMsg() {return msg;}public void setMsg(String msg) {this.msg = msg;}/** * 动态方法调用 * <一句话功能简述> * <功能详细描述> * @return * @throws Exception * @see [类、类#方法、类#成员] */public String login() throws Exception{System.out.println("动态方法调用");HttpServletRequest request=ServletActionContext.getRequest();String username=request.getParameter("username");String password=request.getParameter("password");if("qwe".equals(username)&&"qwe".equals(password)){msg="登录成功,欢迎"+username;return SUCCESS;}else{msg="没有"+username+"用户名信息!";return ERROR;}}public String registe() throws Exception{System.out.println("注册方法调用。。。。。。");HttpServletRequest request=ServletActionContext.getRequest();msg+="注册成功!";return SUCCESS;}}
0 0
- struts的动态方法调用
- struts动态方法调用
- struts动态方法调用
- Struts方法动态调用
- struts中动态方法的调用
- struts 动态调用方法注意事项
- Struts 2 动态方法调用
- 程序动态调用struts国际化资源包键值的方法
- Struts 2读书笔记-----使用Action的动态方法调用
- struts的三种动态方法调用方式,dmi,通配符
- struts的Action接口-- (1)动态方法调用
- struts 2.5 action的多分发 ---动态方法调用
- Struts 2 动态方法调用教程
- struts第四天---动态方法调用
- 【Struts】Action 3 动态方法调用
- struts动态调用方法和集成SessionAware
- struts动态方法调用之感叹号
- struts中的感叹号方式动态方法调用
- C++ 流重定向输出到调试
- 超实用的JavaScript技巧及最佳实践(上)
- xcode plugin
- 希腊字母读法集
- JSP中根据id把input值传到js中
- struts的动态方法调用
- mac 安装 git flow
- ListView的各种使用
- POJ 1003
- SuperMap IObjects C++组件学习笔记(三) - 利用组件绘制的回调方法控制自定义绘制
- iOS中Block介绍(二)内存管理与其他特性
- Java调用Oracle存储过程返回结果集
- 单调递增子序列(二)
- 在手机上配置Android开发调试环境