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 5955407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:06:35+00:00 2026-05-22T18:06:35+00:00

I would like to determine which link is being click, and set a request

  • 0

I would like to determine which link is being click, and set a request attribute accordingly; to be processed in the controller. The controller is generic. It will dispatch to another page according to the attribute set in the JSP. How can I achieve this?

EDIT:

I have followed the BalusC’s advice where

<a href="RandomController/Register">Register</a>
<a href="RandomController/Login">Login</a>

RandomController : 



 @WebServlet(name = "RandomController", urlPatterns = {"/RandomController/*"})
public class RandomController extends HttpServlet {

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
          throws ServletException, IOException {
    int theRandom = 0;
    Random myRandom = new Random();
    RequestDispatcher dispatcher = null;

    String pathInfo = request.getPathInfo();
    String contextPath = request.getContextPath();
    String dispatchesPath = contextPath + pathInfo;

    System.out.println(pathInfo);
    System.out.println(contextPath);
    System.out.println(dispatchesPath);

    theRandom = myRandom.nextInt(MAX_RANDOM);
    request.setAttribute("random", theRandom);

    if(pathInfo.equals("/Login")) {
      dispatcher = request.getRequestDispatcher("Login.jsp");
      dispatcher.forward(request, response);
    }
    else {
      dispatcher = request.getRequestDispatcher("Register.jsp");
      dispatcher.forward(request, response);
    }
  }
}

I have tried this approach but the Exception about maximum depth for nested request dispatchers : 20 is throw.
The generic controller is RandomController which servers two produces random number and set as attribute in request object and sent it to login or register page.

Login.jsp :

<%-- 
    Document   : Register
    Created on : May 28, 2011, 5:49:35 PM
    Author     : nicholas_tse
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  "http://www.w3.org/TR/html4/loose.dtd">

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Online Store Register Page</title>

     <link rel="stylesheet" href="style.css" type="text/css" media="screen" />
  </head>
  <body>
    <jsp:useBean id="randomBean" class="Helper.RandomInt" 
                 scope="request">
    </jsp:useBean>

    <h1>Online Store</h1>

    <p></p>
    <div align="right">
      <h3>
        <c:if test="${not empty sessionScope.username}">
          ! Welcome ${sessionScope["username"]} !
          <form action="LogoutController" method="POST">
            <input type="submit" name="submit" value="Logout"/>
          </form>
        </c:if>
      </h3>
    </div>

    <ul id="nav_list">
      <li><a href="http://localhost:8080/OnlineStore">Home</a></li>
      <li><a href="Product.jsp">Product</a></li>
      <li><a href="">Add Stock</a></li>

      <li><a href="">Shopping Cart</a></li>
      <li><a href="">Order Status</a></li>
      <li><a href="RandomController/Register">Register</a></li>
      <li><a href="RandomController/Login">Login</a></li>
    </ul>     

    <br></br>
    <p></p>

    <c:if test="${!not empty sessionScope.username}">
      <div id="registerForm" align="center" 
           style="border:1px solid black; width:760px" >

        <form name="RegisterForm" action="RegisterController" 
              method="POST">
          <p>
            Username : <input type="text" id="username" name="username"> 
          <c:if test="${message.msg} != null" > 
            ${message.msg}
          </c:if>
          </p>        

          <p>
            Password : <input type="password" id="password" name="password"
          </p>

          <p>
            Name : <input type="text" id="name" name="name"> 
          <c:if test="${message.msg} != null" > 
            ${message.msg}
          </c:if>
          </p> 

          <p>
            Address : <input type="text" id="address" name="address"> 
          <c:if test="${message.msg} != null" > 
            ${message.msg}
          </c:if>
          </p>

          <p>
            State : 
            <select>
              <option>Selangor</option>
              <option>Kuala Lumpur</option>
              <option>Cyberjaya</option>
              <option>Putrajaya</option>
            </select>
          </p>

          <p></p>

          <input type="submit" name="submit" value="Register">
          <input type="reset" name="clear" value="Clear">

          <p></p>

        </form> 

      </div>
    </c:if>
  </body>
</html>
  • 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-22T18:06:36+00:00Added an answer on May 22, 2026 at 6:06 pm

    Without further info the only suggestion I can think of is to add a querystring to your URLs. Like this:

      <a href="mycontroller.do?action=page1">Page 1</a>
    

    This way you can look at the actiuon parameter in the request to determine what to do in your controller.

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

Sidebar

Related Questions

I would like to determine the operating system of the host that my Java
I am battling regular expressions now as I type. I would like to determine
I would like to know how do you determine the hardware needed for a
I would like my GWT program to be able to determine whether it's in
I would like to know if it is possible to determine if a function
I have UITable which contains some UIButtons. I would like a way to use
I would like to call a windows program within my code with parameters determined
Would like to get a list of advantages and disadvantages of using Stored Procedures.
Would like to create a strong password in C++. Any suggestions? I assume it
I would like to test a string containing a path to a file for

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.