Java中写路径

说明:

  webappname:web应用的名称(tomcat目录下webapps文件夹中的项目的名称)

  doSome:url-pattern中的值

1.超链接

<a href="/webappname/doSome"></a>

2.web.xml文件中的url-pattern

<url-pattern>/doSome</url-pattern>

3.form表单的action属性

<form action="/webappname/doSome"></form>

4.ServletContext对象的getRealPath方法

String realPath = application.getRealPath(“/index.html”); 注意:必须保证webapp的根下有index.html

5.web.xml中欢迎页面:欢迎页面比较特殊不以“/”开头,不加webapp名字,除此之外均以“/”开头

<welcome-file-list>
    <welcome-file>html/welcome.html</welcome-file>
</welcome-file-list>

 6.错误页面

<error-page>  
        <error-code>404</error-code>  
        <location>/error/404.html</location>  
</error-page> 

  

原文地址:https://www.cnblogs.com/luna-hehe/p/14519499.html