Web应用程序版本究竟是什么?它有什么影响? [英] What exactly is the web-app version? What does it affect?

查看:175
本文介绍了Web应用程序版本究竟是什么?它有什么影响?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在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维基。但它并没有真正解释我。

Here is the SO wiki for web.xml. But it does not really explain me much.


它允许您在Web应用程序中定义,声明和配置基于Servlet API的
实现,例如servlet,过滤器和
听众。

It allows you to define, declare and configure the Servlet API based implementations in your web application, such as servlets, filters and listeners.

有人可以用简单的例子来解释这个吗?

Can someone explain this with simple examples perhaps?

谢谢。

编辑:

示例web.xml版本控制:

Sample web.xml versioning:

<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">


推荐答案

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 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.

版本控制是指XML模式版本, web.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 - see this answer for example.

有关 web.xml 的具体示例,请参阅:

For concrete examples of web.xml, see:

  • The deployment descriptor: web.xml
  • Sample Web XML application files

这篇关于Web应用程序版本究竟是什么?它有什么影响?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆