You have learnt several servlet related examples. Here we are going to create an example that will call JavaScript function from the servlet. Embedding JavaScript in Servlets can be useful when migrating Web applications that rely on JavaScript to server-side Java without rewriting the business logic.
Description Of Code:
You can see in the given code, we have retrieved database table data into the html tables. We have also embedded delete button in every row of html table to allow the user to select the particular record to delete. This delete button calls the javascript function for the particular record. Before deleting, it will ask the user whether he/she really want to delete the record. If ok, then it will take the id of the specific record and navigate to delteuser.jsp that will delete the record.
Here is the code of Servlet.java:
|
import java.io.*;import java.sql.*; import java.util.*; import javax.servlet.*; import javax.servlet.http.*; public
class
Servlet extends
HttpServlet { |
Here is the code of deleteuser.jsp:
|
<%@page language="java"%> |
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.