My environment: Windows 7 64 bit, Eclipse Kepler, Glassfish 4. My dynamic web project structure outline:
MyProject
|
|__java (src folder)
| |
| |__controller (package)
| |
| |__ControllerServlet.java
|
|__WebContent
|
|__WEB-INF
|
|__view
|__category.jsp
|
|etc...
I enter the url http://localhost:4848/AffableBean/category
into my browser, but it fails and gives me a 404 error. Why does this happen ?
ControllerServlet.java: (snippet only)
@WebServlet(name = "ControllerServlet", urlPatterns = { "/category",
"/addToCart", "/viewCart", "/updateCart", "/checkout", "/purchase",
"/chooseLanguage" })
public class ControllerServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
String userPath = request.getServletPath();
String url = "/WEB-INF/view" + userPath + ".jsp";
System.out.println("test url = " + url);//TEST
try {
request.getRequestDispatcher(url).forward(request, response);
} catch (Exception ex) {
ex.printStackTrace();
}
}
//same code for doPost.
How do I fix this error ? I don't think any request is even hitting the controller servlet.
I solved the problem. When I would access the web app from the localhost:4848, it would take me to index.jsp. I noticed that the url for the web app is http://MyComputerName:6262/AffableBean/
. I added /category to that to make it work. Server port number is 6262, and admin server port number is 4848. I don't really understand this. I never faced this thing when I used tomcat. There was only port number.
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.