Buffalo框架的使用

news/2025/2/14 16:05:46/

整体介绍,建议先看完下面的内容在回过来看这个介绍】当用户输入账号密码后,点击“提交”按钮,则执行JSh中的getInfo()方法,该方法会调用Buffalo框架中的remoteCall("UserService.getInfo",[username,password],function(reply){})方法,"UserService.getInfo":UserService是第六步文件中的,它指定了哪一个类,等价于com.cuc.service,getInfo是UserService指定类中的方法名;[username,password]:是需要传输的参数,使用[arg1,arg2,...]的方式组合;function(reply){}:是Buffalo框架的回调函数,即后台会返回一些数据,可以在该function中获取到。

1.下载Buffalo框架所需要的jsr包和JS文件

https://download.csdn.net/download/qq_34584694/10997810

2.创建一个J2EE的项目,最终目录结构如下

3.index.jsp页面代码:

<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%String path = request.getContextPath();String basepath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html><head><base href="<%=basepath %>" /><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Insert title here</title><script language="JavaScript" src="./scripts/prototype.js"></script><script language="JavaScript" src="./scripts/buffalo.js"></script><script type="text/javascript">var endPoint="<%=request.getContextPath()%>/buffalo";var buffalo = new Buffalo(endPoint);function getInfo(){var username = document.getElementById("username").value;var password = document.getElementById("password").value;buffalo.remoteCall("UserService.getInfo", [username,password], function(reply) {alert(reply.getResult());})}</script></head><body>账号:<input type="text" id="username" />密码:<input type="password" id="password" /><input type="button" value="提交" onclick="getInfo()" /></body>
</html>

4.web.xml配置文件代码:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"><display-name>Buffalo框架的使用</display-name><servlet><servlet-name>buffalo</servlet-name><servlet-class>net.buffalo.web.servlet.ApplicationServlet</servlet-class></servlet><servlet-mapping><servlet-name>buffalo</servlet-name><url-pattern>/buffalo/*</url-pattern></servlet-mapping>
</web-app>

5.User.java代码:

package com.cuc.service;public class User {public String getInfo(String username,String password){if(username.equals(password)){return "欢迎你,"+username;}return "账号或密码不对";}
}

6.buffalo-service.properties文件代码:

####the first buffalo demo
UserService = com.cuc.service.User

7.测试【这里只是一个简单的测试,当账号和密码输入一致时,登录成功,反之,账号和密码有误】


http://www.ppmy.cn/news/628801.html

相关文章

洛谷 AT_abc178_b [ABC178B] Product Max

洛谷 AT_abc178_b [ABC178B] Product Max 1、题目题面翻译题目描述输入格式输出格式样例 #1样例输入 #1样例输出 #1 样例 #2样例输入 #2样例输出 #2 样例 #3样例输入 #3样例输出 #3 提示制約Sample Explanation 1Sample Explanation 2 2、翻译题面&#xff1a; AC代码&#xff…

洛谷P1077摆花

文章目录 一、题目描述二、思路三、代码 一、题目描述 https://www.luogu.com.cn/problem/P1077 题目描述很容易看懂 二、思路 动态规划题目&#xff0c;首先定义状态 dp[i][j]:摆前i种花&#xff0c;一共摆j盆的方案数。 i&#xff1a;1~n j&#xff1a;1~m 需要注意的时&a…

IP地点定位为什么有误差?

随着互联网的不断普及&#xff0c;人们对IP地点定位需求越来越多。然而&#xff0c;即便是在现代技术的支持下IP地点定位仍然存在误差。那么&#xff0c;IP地点定位为什么会出现误差呢&#xff1f; IP&#xff08;Internet Protocol&#xff09;地址是指互联网协议&#xff08;…

数据库技术之MySQL高级

目录 子查询与表连接 子查询(嵌套sql) 利⽤⼦查询进⾏过滤 作为计算字段使⽤⼦查询 外键 表关系 关系表 表联结 联结多个表 使⽤表别名 AS 组合查询 UNION 总结&#xff1a;表联结 练习题 sql_mode sql_mode值的含义 MySQL事务 概述 ⼀,事务的语法 ⼆,事务的…

一篇博客帮你了解MySQL高级知识

MySQL高级 一、子查询与表连接子查询&#xff08;嵌套SQL&#xff09;关系表组合查询 UNION 二、MySQL事务概述事务的语法事务的ACID特性事物的并发问题事物的的隔离级别不同隔离级别的锁的情况&#xff08;了解&#xff09;隐式提交&#xff08;了解&#xff09; 三、MySQL中的…

构建高并发平台架构

一、 设计理念 1. 空间换时间 1) 多级缓存&#xff0c;静态化 客户端页面缓存&#xff08;http header中包含Expires/Cache of Control&#xff0c;last modified(304&#xff0c;server不返回body&#xff0c;客户端可以继续用cache&#xff0c;减少流量)&#xf…

高并发高可用的 架构实践

高并发高可用的 架构实践 一、 设计理念 1.空间换时间 1)多级缓存&#xff0c;静态化 客户端页面缓存&#xff08;http header中包含Expires/Cache of Control&#xff0c;last modified(304&#xff0c;server不返回body&#xff0c;客户端可以继续用cache&#xff0c;减少流量…

局部非饱和性的含义_范里安-微观经济学现代观点讲义(new)

《范里安-微观经济学现代观点讲义(new)》由会员分享,可在线阅读,更多相关《范里安-微观经济学现代观点讲义(new)(114页珍藏版)》请在人人文库网上搜索。 1、Chapter one: Introduction一、资源的稀缺性与合理配置对于消费者和厂商等微观个体来说,其所拥有的经济资源的稀缺性…