我该如何使用<a href=""> tag in a servlet to access an html file?</a>

时间:2014-07-31 15:30:39

标签: html servlets href

我有一个html文件addemployee.html,我需要从servlet调用。

我尝试过以下陈述..但两者都没有起作用:

out.print("<a href='/addemployee.html'>1.Add New Employee</a>");

out.print("<a href=/"addemployee.html/">1.Add New Employee</"a>");

始终收到错误404.html文件存储在与servlet相同的包中。

任何人都可以告诉问题是什么。 任何帮助都将受到高度赞赏。

1 个答案:

答案 0 :(得分:2)

您缺少上下文根。您可以使用以下任何一种方法:

out.print("<a href='addemployee.html'>1.Add New Employee</a>");  // relative if on same level as servlet
out.print("<a href='/WebApplication1/addemployee.html'>1.Add New Employee</a>");  // absolute - hardcoded context
out.print("<a href='" + getServletContext().getContextPath() + "/addemployee.html'>1.Add New Employee</a>");  // absolute - context read from configuration
相关问题