使用Stream类型的Result实现Ajax
来源:互联网 发布:淘宝网仓鼠 编辑:程序博客网 时间:2024/05/08 20:11
Action代码如下:
package org.crazyit.app.action;import com.opensymphony.xwork2.Action;import java.io.*;public class LoginActionimplements Action{//封装请求参数的两个属性private String user;private String pass;//封装输出结果的二进制流private InputStream inputStream;//user属性的setter和getter方法public void setUser(String user){this.user = user;}public String getUser(){return this.user;}//pass属性的setter和getter方法public void setPass(String pass){this.pass = pass;}public String getPass(){return this.pass;}public InputStream getResult(){return inputStream;}public String execute() throws Exception {//判断用户名、密码,生成对应的响应inputStream = user.equals("crazyit.org") && pass.equals("leegang")? new ByteArrayInputStream("恭喜你,登录成功!".getBytes("UTF-8")): new ByteArrayInputStream("对不起,用户名、密码不匹配!".getBytes("UTF-8"));return SUCCESS;}}
struts.xml配置
<?xml version="1.0" encoding="GBK"?><!DOCTYPE struts PUBLIC"-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN""http://struts.apache.org/dtds/struts-2.1.7.dtd"><struts><constant name="struts.i18n.encoding" value="UTF-8"/><package name="lee" extends="struts-default"><action name="loginPro" class="org.crazyit.app.action.LoginAction"><result name="success" type="stream"><!-- 指定下载文件的文件类型 --><param name="contentType">text/html</param><!-- 指定由getResult()方法返回输出结果的InputStream --><param name="inputName">result</param></result><!-- 定义一个名为login的结果 --> <result name="login">/WEB-INF/content/login.jsp</result></action><action name="*"><result>/WEB-INF/content/{1}.jsp</result></action></package></struts>login.jsp
<%@ page contentType="text/html; charset=GBK" language="java" errorPage="" %><%@ taglib prefix="s" uri="/struts-tags" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>使用JSON插件</title><script src="${pageContext.request.contextPath}/jquery-1.4.4.min.js" type="text/javascript"></script></head><body><s:form id="loginForm"><s:textfield name="user" label="用户名"/><s:textfield name="pass" label="密码"/><tr><td colspan="2"><input id="loginBn" type="button" value="提交"/></td></tr></s:form><div id="show" style="display:none;"></div><script type="text/javascript">//为id为loginBn的按钮绑定事件处理函数$("#loginBn").click(function(){//指定向loginPro发送请求,以id为loginForm表单里各表单控件作为请求参数$.get("loginPro" , $("#loginForm").serializeArray() , //指定回调函数function(data , statusText){$("#show").height(80).width(300).css("border" , "1px solid black").css("background-color" , "#efef99").css("color" , "#ff0000").css("padding" , "20px").empty();$("#show").append("登录结果:" + data + "<br />");$("#show").show(2000);},//指定服务器响应为html"html");});</script></body></html>注意要导入jquery-1.4.4.min.js到项目中
0 0
- 使用stream类型的Result实现Ajax
- 使用Stream类型的Result实现Ajax
- Action里result类型Stream的参数配置
- Struts2 result类型为stream见解
- struts中自定义类型为ajax的result标签
- 用stream类型的result组件将验证码图片输入到浏览器
- Struts 2 的stream result用法
- Struts2 result type="stream"的用法
- Struts 2 的stream result用法
- Struts 2 的stream result用法
- result的类型
- struts2的Result类型
- struts2的Result类型
- json类型的result
- Action的Result类型
- Structs2 的Result 类型
- Struts2的Result类型
- Ajax的原生实现关于MIME类型的使用
- 【java技术提高】(1)-- 详解java的四舍五入与保留位
- Android - Download(下载) 项目 详解
- 操作系统面试题的整理
- mybaties基础教程之四:SQL语句映射文件(2)
- 什么是IC卡、M1卡,有啥区别
- 使用Stream类型的Result实现Ajax
- 飞行员配对方案问题(网24题,一)
- Struts功能详解——Action
- Android4.4之Keyguard一LockPatternUtils
- cf——B. Domino Effect
- 广播与多播
- 【java技术提高】(2)-- 理解java的三大特性之封装
- [ M3 LN ] FW(固件)库函数SystemInit() (72MHz)
- Java-ConcurrentHashMap