网络应用程序版本到底是什么?它有什么影响? [英] What exactly is the web-app version? What does it affect?
问题描述
在 Java Web 应用程序中,有一个名为 web.xml 的文件,它有一个版本控制.
In a java web application, there is a file called web.xml and it has a versioning.
这究竟是什么?这有什么用途?
What exactly is this? What is it used for?
这里是 web.xml 的 SO wiki.但这并不能真正解释我太多.
Here is the SO wiki for web.xml. But it does not really explain me much.
它允许您定义、声明和配置基于 Servlet APIWeb 应用程序中的实现,例如 servlet、过滤器和听众.
It allows you to define, declare and configure the Servlet API based implementations in your web application, such as servlets, filters and listeners.
示例 web.xml 版本控制:
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
有人可以用简单的例子解释一下吗?
Can someone explain this with simple examples perhaps?
推荐答案
Web.xml
是您定义 Web 应用程序配置的中心位置.例如,您可以在此处指定:
Web.xml
is a central place where you define the configuration of your Web application. For instance you can specify there:
- servlet 映射,即哪个 URL 路径指向哪个 Java 类(例如,当用户键入 http://something.com/Koray 您可以将该请求指向 KorayServlet.java 类,您可以在其中保留 servlet 的实现)
- 授权参数,例如该用户 Tugay 可以访问 http://something.com/Koray/pictures,但不能访问
http://something.com/Koray/documents - 所有其他安全设置,例如当有人试图打开 http://something.com/Restricted 时,您会将他重定向到 httpsstrong>://something.com/Restricted,即它必须使用 SSL
- 您网站的欢迎页面(例如,当用户输入 http://something.com/Koray 时,您重定向他http://something.com/Koray/index.html)
- servlet mapping, i.e. which URL path refers to which Java class (e.g. when user types http://something.com/Koray you can point that request to KorayServlet.java class where you keep the implementation of the servlet)
- authorization parameters, e.g. that user Tugay has access to http://something.com/Koray/pictures, but not to http://something.com/Koray/documents
- all other security settings, e.g. when someone tries to open http://something.com/Restricted, you redirect him to https://something.com/Restricted, i.e. it has to use SSL
- welcome page of your Web site (e.g. when user types http://something.com/Koray you redirect him to http://something.com/Koray/index.html)
我还建议研究 Servlet 3.0 规范,其中许多参数可以通过注释设置.
I would also suggest researching Servlet 3.0 specification, where many of these parameters can be set through annotations.
版本控制是指您的 web.xml
文件的语法必须遵守的 XML 模式版本.更重要的是,它还指示您的应用程序实现的 Servlet 规范的版本.符合 Servlet 3.0 的 web.xml
应该如何开始的示例:
Versioning refers to XML schema version that syntax of your web.xml
file must obey. More important, it also indicates the version of Servlet specification that your application implements. An example how Servlet 3.0-compliant web.xml
should begin:
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
大多数 IDE 会自动生成 web.xml
的那部分.如果由于某种原因要手动更改它,请注意匹配 web-app 和 xsd 的版本.
Most IDEs will automatically generate that part of web.xml
. If you are going to change it manually for some reason, be careful to match the versions of web-app and xsd.
web.xml
的具体例子见:
这篇关于网络应用程序版本到底是什么?它有什么影响?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!