Win a copy of Emmy in the Key of Code this week in the General Computing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Cannot access servlet after deploying website on cpanel

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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!
 
Marshal
Posts: 67295
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have no idea what "cpanel" is, but it sounds like you have two major problems:

  • Relying on the Invoker to access servlets rather than mappings in the deployment descriptor. Bad idea. Very bad idea.
  • Using page-relative URLs in your JSPs. All URLs to internal resources should be server-relative; that is, starting with the context path.


  • See the Servlets FAQ and the JSP FAQ for more details on both of these issues.
     
    shafidah shafiee
    Greenhorn
    Posts: 3
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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:
    - public_html
    - images
    - WEB_INF
    - classes
    - lib

    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");
    dispatcher.forward(request, response);

    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.
     
    Bear Bibeault
    Marshal
    Posts: 67295
    170
    Mac Mac OS X IntelliJ IDE jQuery Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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.
     
    All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
    Java file APIs (DOC, XLS, PDF, and many more)
    https://products.aspose.com/total/java
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!