简体   繁体   中英

how do i use <a href> tag in a servlet to access an html file?

I have a html file addemployee.html which i need to call from a servlet.

I have tried following statements .. but neither are working:

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

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

Always getting error 404.The html file is stored in the same package as the servlet.

Can anyone please tell what the problem could be. Any help would be highly appreciated.

You are missing context root. You can use any of the following:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM