[英]Tomcat context path issue
I deployed application in tomcat under webapps/testing1 folder. 我在tomcat的webapps / testing1文件夹下部署了应用程序。
http://localhost:8080/testing1/index.html HTTP://本地主机:8080 / testing1 / index.html的
This html page has anchor tag with href as "/login" 该html页面具有带有href的锚标记为“ / login”
When I click on anchor, it takes to localhost:8080/login instead of localhost:8080/testing1/login 当我单击锚点时,它将转到localhost:8080 / login而不是localhost:8080 / testing1 / login
I did not do any change in tomcat conf xmls. 我在tomcat conf xmls中没有做任何更改。 How can I make all paths starts with slash would goto application context? 如何使所有以斜杠开头的路径进入应用程序上下文?
Suggestions would be appreciated. 建议将不胜感激。
By declaring a link href="/login"
you make that an absolute link on your host. 通过声明链接href="/login"
您可以将其作为主机上的绝对链接。 If you want login inside your app you'd have to prepend the context path ( request.getContextPath ()
) or use relative links ( href="login"
) 如果要在应用程序内部登录,则必须添加上下文路径( request.getContextPath ()
)或使用相对链接( href="login"
)
If you deployed context successfully in Tomcat and it is Start up successfully. 如果您在Tomcat中成功部署了上下文,并且它是“启动成功”。 Then the Application access directly the web.xml from the WEB-INF folder. 然后,应用程序直接从WEB-INF文件夹访问web.xml。
It access the servlet using the <url-pattern>
and <servlet-class>
to identify the servlet. 它使用<url-pattern>
和<servlet-class>
来访问servlet以标识该servlet。
If you are worrying about accessing HTML files from the servlet you can access them directly from the context path. 如果您担心要从servlet访问HTML文件,则可以直接从上下文路径访问它们。
ie 即
if file present at CONTEXT/html/file1.html
you can access it as html/file1.html
如果文件存在于CONTEXT/html/file1.html
,则可以将其作为html/file1.html
if file present at CONTEXT/file2.html
you can access it as file2.html
如果文件存在于CONTEXT/file2.html
,则可以将其作为file2.html
进行访问
You have to specify the .
您必须指定.
prefix to the href
value. href
值的前缀。
<a href="./login">
so that the URL will be localhost:8080/testing1/login
<a href="./login">
以便该URL为localhost:8080/testing1/login
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.