• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to hide the Jsp page name?

 
mallikarjun dontamsetti
Ranch Hand
Posts: 246
Firefox Browser Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
    Bartender
    Posts: 543
    4
    Java Netbeans IDE Redhat
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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.
     
    ellie spring
    Greenhorn
    Posts: 24
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    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.


     
    mallikarjun dontamsetti
    Ranch Hand
    Posts: 246
    Firefox Browser Oracle
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Yes i used servlet as a controller


    And it is displaying the jsp name(studentinformation.jsp) in address bar of my browser
     
    Dieter Quickfend
    Bartender
    Posts: 543
    4
    Java Netbeans IDE Redhat
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 246
    Firefox Browser Oracle
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Is there any other way?
    And what about login page and home page
    I used RequestDispatcher but it displaying Servlet Name
     
    Dieter Quickfend
    Bartender
    Posts: 543
    4
    Java Netbeans IDE Redhat
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 246
    Firefox Browser Oracle
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 246
    Firefox Browser Oracle
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Bartender
    Posts: 543
    4
    Java Netbeans IDE Redhat
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Pie
    Posts: 65120
    91
    IntelliJ IDE Java jQuery Mac Mac OS X
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic