#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Posts
    4
    Rep Power
    0

    JSP passing id parameter within a link


    I have a webpage that dynamically generates a list of courses from our database using a stored procedure to do all the sql statements. I am only a beginner so my supervisor sets up all the hard stuff and I just call stored procedures and pass them parameters or get parameters from them. I want each course to link to a detail page. My course detail page is going to be generated dynamically from 3 tables on the database but from a beginner's point I am forwarding to a static page for now. I am trying to pass the course ID when the user clicks the course link.

    The code I'm using to generate the course list is:
    <td>
    <a href="<%= CONTROLLER %>?service=<%= SVCPREFIX %>olcourses.OLCourses&target=<%= WEB_NAME %>/olcourses/courseDetails.jsp&mode="clientcoursedetails"
    &CourseID="<%=display_courses.get("CourseID")%>">
    <%=display_courses.get("CourseTitle")%></a>
    </td>

    Display_courses.get prints the course title in my table. CONTROLLER, SVCPREFIX and WEB_NAME are constants in a jsp page I import. They define paths I use repeatedly. olcourses.OLCourses is my class file that calls the stored procedure I call in if statements that test the mode. So I can use one class file to get a list of courses, get course details, add, update or delete courses, etc. The mode is used to get the correct stored procedure.

    The previous index page has a submit button calling a stored procedure to get 4 parameters from the database and put them in a hashmap. I use display_courses.get("CourseTitle") to get the name of the course and I figure I can use the same line to get CourseID and pass it to the detail page.

    I get the static course details page to display but the url at the top says "http://localhost:8080/conestoga/servlet/Controller?service=edu.conestoga.web.olcourses.OLCourses&target=/web/olcourses/courseDetails.jsp&mode=". It looks to me like it is cutting off part of the url. And my course ID is after the mode so I am not getting the course ID to start generating the next page.

    Am I doing somethign wrong that is cutting this off prematurely? Is there a way to use a session to pass the courseID? I am only used to passing parameters using form and hidden input tags so I'm not sure how to get a link to pass the courseID or to use a session to pass it.

    Any advice is greatly appreciated!
    Linda
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Posts
    4
    Rep Power
    0
    Ok, I figured it out. I kept getting my link cut off at &mode=. If I tried to put the CourseID in front I'd get cut off at &CourseID=. So I put both of those in variables.

    <% String CourseID = (String)display_courses.get("CourseID");
    String passMode = "clientcoursedetails"; %>

    Then I just used the variables.
    &mode=<%=passMode%>
    &CourseID=<%=CourseID%>

    and it finally worked

IMN logo majestic logo threadwatch logo seochat tools logo