B/S网络架构中有APP吗
时间: 2023-07-20 18:26:33 浏览: 49
在B/S网络架构中,一般不使用APP,而是通过浏览器访问Web应用程序。APP通常是指运行在移动设备上的本地应用程序,而B/S架构中的Web应用程序是运行在服务器上的应用程序,通过Web浏览器进行访问和交互。不过,有些Web应用程序可能提供移动端的适配,即提供移动端的Web界面,以便在移动设备上使用,但这并不等同于APP。
相关问题
web是B/S架构,app是C/S架构,那微信小程序是什么架构
微信小程序是一种类似于B/S架构和C/S架构的混合架构,也被称为“轻量级应用架构”。它在用户端采用类似于B/S架构的方式,通过浏览器访问微信服务器上的应用,而在开发者端采用类似于C/S架构的方式,开发者需要使用专门的IDE进行开发和发布。微信小程序的代码运行在微信客户端的JS引擎中,能够实现与微信客户端的交互,并且具有一定的离线能力。因此,微信小程序的架构可以认为是一种混合的、轻量级的、客户端和服务端共同实现的架构。
B/S架构的实现代码用例
以下是一个简单的B/S架构实现的代码用例,使用Java语言和Spring框架:
1. 前端代码(HTML、CSS、JavaScript):
```html
<!DOCTYPE html>
<html>
<head>
<title>B/S Architecture Example</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
</head>
<body>
<div class="container mt-5">
<h1>B/S Architecture Example</h1>
<div class="form-group">
<label for="input-text">Enter some text:</label>
<input type="text" class="form-control" id="input-text" placeholder="Type something...">
</div>
<button type="button" class="btn btn-primary" onclick="sendText()">Send</button>
<hr>
<div id="output"></div>
</div>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@3.2.0/dist/tf.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/universal-sentence-encoder@4.2.0/dist/universal-sentence-encoder.min.js"></script>
<script src="app.js"></script>
</body>
</html>
```
2. 后端代码(Java + Spring):
```java
package com.example.bsaexample;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.tensorflow.Tensor;
import org.tensorflow.Tensors;
import org.tensorflow.framework.ConfigProto;
import org.tensorflow.framework.GPUOptions;
import org.tensorflow.framework.Session;
import org.tensorflow.framework.Session.Runner;
import org.tensorflow.framework.TensorShape;
import java.util.Arrays;
@SpringBootApplication
@RestController
public class BsaExampleApplication {
public static void main(String[] args) {
SpringApplication.run(BsaExampleApplication.class, args);
}
@PostMapping(value = "/predict", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public String predict(@RequestBody String input) {
GPUOptions gpuOptions = GPUOptions.newBuilder().setVisibleDeviceList("0").build();
ConfigProto configProto = ConfigProto.newBuilder().setGpuOptions(gpuOptions).build();
try (Session session = Session.create(configProto.toByteArray())) {
Tensor<String> inputTensor = Tensors.create(new String[] { input });
Runner runner = session.runner().feed("input", inputTensor).fetch("output");
Tensor<Float> outputTensor = runner.run().get(0).expect(Float.class);
float[] output = outputTensor.copyTo(new float[1][512])[0];
return Arrays.toString(output);
} catch (Exception e) {
e.printStackTrace();
return "Error: " + e.getMessage();
}
}
}
```
3. 前后端交互代码(JavaScript):
```javascript
async function sendText() {
const input = $("#input-text").val();
if (input.trim() !== "") {
$("#output").text("Loading...");
const output = await predict(input);
$("#output").text(output);
}
}
async function predict(input) {
const model = await tf.loadGraphModel("model/model.json");
const encoder = await use.load();
const encodedInput = await encoder.embed([ input ]);
const inputTensor = tf.tensor(encodedInput);
const outputTensor = model.execute({ "input": inputTensor });
const output = await outputTensor.array();
return output;
}
```
这个例子实现了一个简单的文本编码预测功能,用户在前端输入一段文本,通过JavaScript调用后端的REST API进行计算,后端使用TensorFlow进行计算并返回结果。这个例子还包括了一些常见的开发框架和库,如Spring、Bootstrap、jQuery、TensorFlow.js和Universal Sentence Encoder。