Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6005185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:21:54+00:00 2026-05-23T01:21:54+00:00

I am having a weird problem here, and I am really stuck, need to

  • 0

I am having a weird problem here, and I am really stuck, need to get this work badly.

so i have a page say index.jsp with a link say “a href=servlet?id=10”. when I click on this link it will go to doGet() on my servlet and here is the code in my servlet.

protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
                 String action = request.getParameter("id");
                  // search database and create an arraylist
                        if(//user logged in)
                        address = "s/results.jsp";
                        else   
                        address = "results.jsp";
                   // set arraylist in session object
                RequestDispatcher dispatcher = request.getRequestDispatcher(address);
                dispatcher.forward(request,response);
     }

So the above code works fine but after request forwarding, my browser shows the url as

http://localhost/project/servlet?id=10.

I don’t want the above url as i am forwarding to two different jsp’s based on the user login status one is in ‘s’ folder and other is outside of that.
if user is logged in then i forward to ‘s/results.jsp’ and if user is not logged in i am forwarding to ‘results.jsp’.

in case of s/results.jsp i am accessing resources like images and scripts from outside of ‘s’ folder by using ../ in the results.jsp.

as url is not changing to s/results.jsp , i am unable to access the resources with ‘../’
and as i am using jsp pagination , when i click next the url is changing to s/results.jsp
and in that case i am able to access resources using ../

one solution in my mind is to copy all resources in s folder , but that would increase
redundancy.

one other solution in my mind is to create two different servlets for two jsp’s
but i don’t know where to put the servlet so that it can access resources outside of s folder with ../

is their any other good way i can do the task..

I have tried to find information about this but haven’t been able to figure it out.

Any help will be very much appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T01:21:55+00:00Added an answer on May 23, 2026 at 1:21 am

    You have basically instructed your webbrowser to send a request to exactly that URL. The forward does not change the URL. It is entirely server side. Apart from using response.sendRedirect() instead -which would trash the current request, including all of its attributes, and create a brand new request on the given URL-, you could also just change your link to <a href="results?id=10">, or when the user is logged in, to <a href="s/results?id=10">.

    <a href="${user.loggedin ? 's/' : ''}results?id=10">
    

    Finally alter the servlet mapping accordingly so that it get invoked on those URLs.

    <url-pattern>/results</url-pattern>
    <url-pattern>/s/results</url-pattern>
    

    You’ll only miss the JSP extension. But JSPs which are to be used by a dispatcher belong in /WEB-INF folder anyway so that they cannot be viewed by the enduser directly without invoking the servlet first. You also end up with nicer URLs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.