I recently came into contact with a C# project, which is basically an MVC structure and a web project based on asp.net. The view layer is composed of multiple cshtml files (basically can be considered as the previous aspx files), the controller layer is composed of multiple cs files (c# code), and the data layer will not be discussed here.
This project is like this. I took a quick look. For example, in the cshtml file of the view layer, a certain button will be linked to a certain function in the js file, and then this function will submit a post request or a get request, and then it will Link to the corresponding function in the cs file of the controller layer, and then process the data and return.
Now there are several confusions:
1. I don’t know if the process mentioned above is a mainstream front-end and back-end interaction process in web development now?
2. Is the jsp technology based on java web similar to the above .net process? Does the jsp file correspond to the cshtml file in .net? However, it is said on the Internet that jsp files will contain java code, but I did not find any c# code in the cshtml file. It was either html or js
3. If the jsp file contains a lot of java code, wouldn't the view layer and the controller layer be stuck together? Shouldn't it be a process where the jsp file calls js, and then js calls the java file in the server-side controller layer?
4. If it is true that the jsp file in question 3 contains a large amount of java code, then it is indeed not well decoupled. Then for the .net project I just mentioned, does such a process mean the front and back? Is end-to-end decoupling pretty good?
5. What I am a little bit puzzled about is why I can’t find a single html file in that .net project. They are all cshtml files, and then there are a large number of js files and cs files (c# code).
Thank you everyone, I am actually a newbie who has just entered the world of web development
phpcn_u15822017-05-17 10:02:59
Thank you for the invitation. The following is my humble opinion. If you want to spray, please spray lightly:
That’s right. But now there is separation of front and back ends
Yes; No, cshtml
应该对应是java中的velocity
If mixed in, it will. You can make jsp correspond to a servlet
Yes, it’s pretty good
This is a template that will simply make HTML development more friendly to our backend staff
PHPz2017-05-17 10:02:59
That's it. Because I have experience, I will give an answer:
1. What you said about linking to a js file including a css file is because the recognition path is defined in c#, otherwise it will not be recognized.
2. cshtml is Razor syntax, and the file name suffix is required to be this.
3. I have never encountered a .net project mixed with Java. However, it is still recommended to use pure C# since it is .net, which is also easier to maintain.
4. All your doubts now stem from your lack of understanding of the backend. As a front-end, if you have time, you can learn Node’s express framework or koa. Use template syntax, and you will understand your current doubts.
phpcn_u15822017-05-17 10:02:59
It is a classic front-end and back-end interaction architecture, but the current mainstream has migrated to the spa direction. The front-end is responsible for processing more routing and logic, and the back-end is only responsible for providing api and data;
jsp and cshtml can be said to be the same in this sense, but the details are different; as for why there is no c# in cshtml, it is because Microsoft stipulates that the View layer uses the razor engine, and the suffix is cshtml. In addition to standard html and js, razor can also be used. syntax (note that it is not C#), but according to the current trend, more and more people do not use the back-end to generate pages, but process them directly on the front-end, so there are no razor statements in many cshtml;
Jsp mixed with java is an analogy with asp, which is an obsolete technology. The questioner has accepted the concept of mvc, and the question raised is correct, so no one does it now;
Yes;
Because it is stipulated by Microsoft, see 2 for specific reasons; html files can also exist, but using cshtml can be bound to the controller by default, which is more convenient;
習慣沉默2017-05-17 10:02:59
This problem is the separation of front and back ends. The current mainstream is MVC three-layer separation.
As for the JSP you mentioned, it is actually an early form of Java that embeds Java code in HTML. This method of use has now been slowly weakened.