首先我们抛开淘宝的nodejs作中间层的前后端分离。
前后端分离,前后端通过 JSON 来交流,
那么页面是什么文件(html,shtml,jsp,还是其它)
那么页面跳转前端来跳还是后端来跳
如果前端来跳,那怎么保持会话(登录状态如何带到下个页面)。
回复内容:
首先我们抛开淘宝的nodejs作中间层的前后端分离。
前后端分离,前后端通过 JSON 来交流,
那么页面是什么文件(html,shtml,jsp,还是其它)
那么页面跳转前端来跳还是后端来跳
如果前端来跳,那怎么保持会话(登录状态如何带到下个页面)。
挨个儿简单回答?
首先我们抛开淘宝的nodejs作中间层的前后端分离
“淘宝的nodejs”,什么玩意儿,是alinode
么?这和前后端分离也没什么关系啊!
前后端分离,前后端通过 JSON 来交流
没毛病,可以实现,也是常见策略
那么页面是什么文件(html,shtml,jsp,还是其它)
通常真的就是html
了,你想想,前后端已经分离,也就是说面对用户请求,不再对接你的什么tomcat
,express/koa/toa
等server了,谁来帮你做渲染?答案是没有。前后端分离后,渲染工作被拿到了前端(浏览器),浏览器能读什么?只能是html
。
那么页面跳转前端来跳还是后端来跳
前端、后端其实都可以。前端就是最简单的#
做路由标识符,或者高级点用html5 mode
(AngularJS
里的叫法);后端就是nginx
之类的“网关”服务做路由转发。具体哪种方式,取决于你的解决方案是怎么样的,你的需求是怎么样的。
如果前端来跳,那怎么保持会话(登录状态如何带到下个页面)
如果只做前端路由,页面都不重载,保持状态还不简单,存一个全局变量可不可以?用localStorage
可不可以?用cookie
可不可以?其实方式有的是,最终还是要看你的具体业务场景
解决方案有很多,我就说个简单的。
页面文件,既然不用node,那就直接 html 好了。 可以通过一些前端模块来渲染,比如 handlebars。后端只需要输出json。
页面跳转。既然是前后端分离,那么后端专心提供数据好了,路由交给前端。
保持会话。如果你只是需要保存登录状态的话,只需要浏览器存储 session,每次跳转页面都去校验 session 有效性就行了。 相应的, 后端提供一个session校验接口。
但是其实这样算不上前后端分离,想想,html是由某个后端负责的吧,那么这个后端和提供数据的后端,不能在一起吧,否则又搅和在一块了。
所以,还是得有个专门的后端server来扮演前端的相关资源管理这个服务。我们团队也是用node来做,为什么呢? 因为比较省事。
java 后端不需要再提供json接口了,他们只需要按照业务数据特性编程。node这一层可以简单的封装一下,提供适合页面使用的接口。
数据校验,前后端可以共享数据校验模块,因为都是 js。
路由,html等等资源,都是由前端直接管理,而前端团队也是直接和产品经理直接沟通,快速反馈。如果这一部分需要后端的介入,就比较困难了。
以上是我们收获到的一些好处,更多的更好的,想必阿里的团队总结的很全面了。这里就不复制黏贴了。
以上。
1、所有页面都是静态的HTML文件,所有交互在前端做,包括跳转
2、网页公共的部分,比如网页头部,底部在nginx那里做。参考nginx的SSI模块。
3、会话状态,ajax调登录接口后,写一个本地cookie。
页面是什么文件: 浏览器里面看到的总是html代码。
页面跳转前端来跳还是后端来跳:web服务器来跳,跳转请求永远要发送给web服务器处理,但是js效果不属于该情况(如html块的显示/隐藏)
怎么保持会话:cookie中的session_id或者专门定义的token,这代表了当前用户的身份,也是session_id劫持的作用原理。
很多新手会有各种前后端分离的问题,但是首先要搞清楚什么是前端,什么是后端。在不同的场景下,它们的意思其实是不一样的。
就代码来说,通常前端指最终html,后端指服务器脚本。此时前后端分离是指html部分和服务器脚本松耦合。
而对于系统来说,前端是指与访问者交互的部分,后端是指数据处理部分。此时前后端分离是两个系统间的松耦合,由于session的特性决定了它不适合这个模式,所以token是通常的选择,此时前后端通信与你的网站访问微信API是相似的逻辑。
1.如果是前后端分离的话,那一般是前端跳转
2.怎么保持会话?浏览器的话简单的办法就是验证session,还可以用本地cash
1.既然已经采用前后端分离, 那前端部分应当完全独立于后端, 跳转也应由前端实现
2.页面是什么文件取决于你的决定, 你可以是html, 也可以是jade, 甚至可以是你自己实现的格式, 但是你就要实现你的模版引擎, 最终浏览器展示的, 一定是html格式的文件
3.登录状态的保存, 需要前后端配合, 主要在于后端是如何判断前端的登录状态的, 微信api的实现,是url中必须带上?access_token=[xxx]来判断状态的, 这样你就需要每个api提交都带上access_token参数。如果后端是通过cookie判断,那么前端就需要在cookie中保存状态

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python are both high-level programming languages that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software