Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

passing id from jsp to servlet through url  RSS feed

 
Dinesh Ravi
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

i was send the id through url like this code.

<td> <%=rs3.getString("Project")%> </td> <td> <a href="TaskAssignment.jsp?id=<%=rs3.getString("id")%>"> <input type="button" name="edit" value="Edit"></a></td>

i have problem to getting this id in servlet.

Servlet:

String id=request.getParameter("id");

the variable id getting only null
 
s ravi chandran
Ranch Hand
Posts: 561
6
Java jQuery
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried this:

<td>Project 1</td>
<td><a href ="TaskAssignmentServlet?id=5"> sometext
<input type="submit" name="edit" value="Edit">
</a></td>


I think here in jsp code, you forgot to add the hyperlink text.. either way. from the given jsp code, I am getting the value in the servlet. also, the hyperlink is refering to JSP not SERVLET. is that what you missed?



 
Dinesh Ravi
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i tried but i did't get the id value. it's value is null.

i was created a jsp page like taskAssign.jsp

this page getting a value and send values to servlet page for insert values to database. tha taskAssign.jsp page to show what are the data's inserted the database. if i want to update this details click the edit button. it's appers taskAssign.jsp?id=2 like this values are showing. if i click update the servlet page getting id value is null.

taskassign.jsp

Employee Name: <select name="empname" required="">
<option selected value="">Select Employee</option>
<% while(rs.next()){ %>
<option value="<%=rs.getString("EmpId")%>" <% if(emp.equals(rs.getString("EmpId"))) {%> selected <% } %>><%=rs.getString("EmpName")%></option>
<% } %>
</select><br>
Project Name: <select name="project" required="">
<option selected value="">Select Project</option>
<% while(rs1.next()){ %>
<option value="<%=rs1.getString("ProjectName")%>" <% if(proj.equals(rs1.getString("ProjectName"))) {%> selected <% } %> > <%=rs1.getString("ProjectName")%></option>
<% } %>
</select><br>

llike this.

same page showing the inserted values:

<tr>
<td>Project</td> <td>Employee</td><td>Task</td><td>Due Date</td> <td>Edit</td>
</tr>

<% while(rs3.next()){%>
<tr>
<td> <%=rs3.getString("Project")%> </td> <td><%=rs3.getString("EmpId")%></td><td><%=rs3.getString("Task")%></td><td><%=rs3.getString("DueDate")%></td> <td> <a href="TaskAssignment.jsp?id=<%=rs3.getString("id")%>">Click<input type="button" name="edit" value="Edit"></a></td>
</tr>

this code no problem.

i need to get the id value in servlet.
 
J. Kevin Robbins
Bartender
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your first step, and this is very important, is stop writing scriptlet code. Learn how to create a properly structured web application.

Start by ready this and this.
 
Dinesh Ravi
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your suggestion.

And i got the id value.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!