aspose file tools*
The moose likes JSP and the fly likes How to hide the Jsp page name? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "How to hide the Jsp page name?" Watch "How to hide the Jsp page name?" New topic
Author

How to hide the Jsp page name?

mallikarjun dontamsetti
Ranch Hand

Joined: Mar 18, 2011
Posts: 242

Hi all I am new to jsp and servlets i have doubt about the name display in URL.
When i am observing some websites the name of the page will not appears in the URL but when i am clicking links or buttons in my application my JSP page names displays in URL how to avoid it?

ex:
  • http://localhost:xxxx/ComplexSearch-malli-context-root/login.html?reload
  • http://localhost:xxxx/ComplexSearch-malli-context-root/complexsearch.jsp

  • Dieter Quickfend
    Ranch Hand

    Joined: Aug 06, 2010
    Posts: 359
    You should really use servlets as controllers. You control your url with mapping a url to a servlet in web.xml and redirecting from that servlet to your JSP.


    Oracle Certified Professional: Java SE 6 Programmer
    Oracle Certified Expert: Java EE 6 Web Component Developer
    Oracle Certified Expert: Java EE 6 Enterprise JavaBeans Developer
    ellie spring
    Greenhorn

    Joined: Jun 15, 2011
    Posts: 24

    Link to your servlet from your <a> tag.
    like this

    Assuming you have mapped your servlet correctly.
    Then the servlet handles the display by using RequestDispatcher object.
    Then forwards your request and response to your jsp page.

    lets say your servlet is named ResultServlet
    here is the sample code in a servlet


    It will display the result.jsp upon succesful load.
    Hope this helps.



    "Nothing is impossible, impossible takes a little longer".
    mallikarjun dontamsetti
    Ranch Hand

    Joined: Mar 18, 2011
    Posts: 242

    Yes i used servlet as a controller


    And it is displaying the jsp name(studentinformation.jsp) in address bar of my browser
    Dieter Quickfend
    Ranch Hand

    Joined: Aug 06, 2010
    Posts: 359
    Ok, I can work with this.

    First of all, there is a huge difference between

    and


    Basically, the former will send a response to the browser telling him to make a new request to that page. The browser will create a new request to the JSP you mentioned in your method call, and you have essentially used no controller to go to the page.

    The latter will NOT send the response directly to the browser, but it will redirect your request to the jsp page, keeping all your request parameters and attributes, and not updating your url bar so the address you mapped your servlet to is used as the url in the browser bar.

    You should almost always use the latter.
    mallikarjun dontamsetti
    Ranch Hand

    Joined: Mar 18, 2011
    Posts: 242

    Is there any other way?
    And what about login page and home page
    I used RequestDispatcher but it displaying Servlet Name
    Dieter Quickfend
    Ranch Hand

    Joined: Aug 06, 2010
    Posts: 359
    that is the way you do it. You can direct your home page to a servlet. You shouldn't link to a login page.

    It is displaying the servlet name because you're using the servlet name as a URL-mapping in your web.xml.

    In your web.xml, you'll have the following elements:



    The url you want to link to, the url you want to appear in your browser, is the <url-pattern> tag. You just change its content to what you want to display in your browser bar.
    mallikarjun dontamsetti
    Ranch Hand

    Joined: Mar 18, 2011
    Posts: 242

    It is also showing the action name i have used in my servlet appended at the jsp page
    like
    <c:url value="masterdetailservlet?action=employeeShow&DEPTNO=${dept.DEPTNO}" var="urlCurr"/>

    else if(Action.equals("employeeShow")){

    ------
    -------
    }
    it is showing in URL like ..../../../action=employeeShow&DEPTNO&XXXXX
    mallikarjun dontamsetti
    Ranch Hand

    Joined: Mar 18, 2011
    Posts: 242

    Is there any methode or something like post (which we actually used in servlets) in JSP (Not for form) for hiding data sending from jsp to servlet
    Dieter Quickfend
    Ranch Hand

    Joined: Aug 06, 2010
    Posts: 359
    I think you're confused as to what JSP actually is. A JSP is basically a servlet that writes HTML to its outputstream. What you actually is comprised of HTML, JSP is not a markup language, it's a server-side technology. Perhaps it is best to read a course book or follow some tutorials to learn how to work with JSP.
    Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 60053
        
      65

    Read this article and this article.


    [Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: How to hide the Jsp page name?
     
    Similar Threads
    Welcome Filelist - with Spring
    login-config not prompting for user id and password
    Default Server port assignments in WSAD
    AJAX Problem in JSP
    About JAMon Usage