Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cannot access servlet after deploying website on cpanel

 
shafidah shafiee
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!
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64701
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • 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
    Author and ninkuma
    Marshal
    Pie
    Posts: 64701
    86
    IntelliJ IDE Java jQuery Mac Mac OS X
    • 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.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic