This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I deployed my website via cpanel recently. All the jsp files are located in the public folder and the servlets are in the WEB-INF/classes subfolder. My home.jsp page cant seem to make a call to any servlets. An error message states that the resource is not found. I managed to find a solution to this:- use servlet/Login or servlets/Login (I have no idea why since there is no folder called servlet in the first place). Anyway, the servlets can be accessed but now I have a problem passing the control back to a Jsp. Using requestDispatcher will take me to www.domain.com/servlet/newjsp.jsp instead of www.domain.com/newjsp.jsp . Any idea how I can solve this? Thanks in advance!
Sorry I dont really get what you mean.. I'm trying to deploy a website via an interface called cpanel that is provided by the hosting co.
The directories I have at the moment are:
My JSP files are in the public_html folder and servlets are in the classes folder.
On my home.jsp i have the following form:
<form name='LoginForm' action='servlet/UserLogin'> ... </form>
(initially I wrote the action attribute as='UserLogin' but it returns an error saying resource is not found. According to e hosting co I need to specify the action attribute as above. Its kinda strange as I dont have a servlet folder to begin with. Anyway it works.)
So upon submission of the form I'll get to the UserLogin servlet. At the end of the servlet, I used the following to return control to my home page:
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/home.jsp");
But this will take me to www.domain.com/servlet/home.jsp which is non-existent.
Any idea how I can resolve this? My hosting co doesnt seem to know what theyre doing.. unfortunately.
Problem #1: How are you mapping the servlets in the deployment descriptor?
Problem #2: action='servlet/UserLogin' ⇐ this is page-relative URL. Bad news! You should be using server-relative URLs that being with the context path. But you need to solve problem #1 -- the servlet mappings -- before you can tackle the URLs.