aspose file tools*
The moose likes Servlets and the fly likes Cannot access servlet after deploying website on cpanel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Cannot access servlet after deploying website on cpanel" Watch "Cannot access servlet after deploying website on cpanel" New topic
Author

Cannot access servlet after deploying website on cpanel

shafidah shafiee
Greenhorn

Joined: Mar 04, 2011
Posts: 3
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

Joined: Jan 10, 2002
Posts: 61221
    
  66

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.


    [Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
    shafidah shafiee
    Greenhorn

    Joined: Mar 04, 2011
    Posts: 3
    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

    Joined: Jan 10, 2002
    Posts: 61221
        
      66

    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.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Cannot access servlet after deploying website on cpanel