Reputation: 634
how do i access a servlet in a form that is located in a subfolder. Here's how did it.
<form action="../login" method="post">
It worked but the stylesheet that was located in a folder named css located in the web-inf folder is not working. Here's is the structure of my directory
WebContent/css/style.css
WebContent/jsp/login.jsp
In the login page here is the code that embeds the css
<link href="../css/style.css" rel="stylesheet">
When i moved the style.css out of the css folder it worked. I think it is trying to look for style.css in the root folder.
Upvotes: 1
Views: 2171
Reputation: 26
You can simply change the link code of CSS.
<link href="projectname/css/style.css" rel="stylesheet">
instead
<link href="../css/style.css" rel="stylesheet">
style is connect.
If you have any named folder then just you connect like this:
project-name/folder_name/file.extension
Upvotes: 0
Reputation: 11223
The WEB-INF folder is private to the user browser, the browser cannot access any JSP, CSS, HTML or whatever file placed in that folder, that is by design.
Sometimes JSP files are placed inside WEB-INF folder to enforce to access them through a servlet in a MVC style. In that case, you must map a URL to a servlet and then the servlet will forward to the JSP inside the WEB-INF folder like this:
// Map this servlet to URI /foo/login
class LoginServlet extends HttpServlet{
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response){
...
RequestDispatcher dispatcher = request.getRequestDispatcher("/WEB-INF/WebContent/login.jsp");
dispatcher.forward(request, response);
}
}
Anyway, do not place the static HTML assets (HTML, CSS, GIF, ...) inside WEB-INF folder, only JSP files.
If your application is very simple, you may not benefit from a MVC architecture, then just move the WebContent folder, JSP files included, out of the WEB-INF folder, and you will be able to access JSP files directly.
Upvotes: 2