javascript for textbox or prompt using servlet

javascript for textbox or prompt using servlet

Dear sir
I am writing script in servlet,so prompt() is not working here so please help me...In my project when a vendors want to delete the uploaded file ,if they are confirmed to delete the i have to take a reason for deleting a textbox as to come if press ok then delete the file then i have to store that reason in a data base so how to do in servlet.please help
me..

My code is as follows
out.println("function del(path,xxx){");
out.println(" var Cv = null;");
out.println(" Cv = confirm(\"Are you sure to delete the file?\");");
out.println(" if(Cv){");
out.println("if(path == \"detach\"){");
out.println(" var reason=prompt('Reason for deleting:','')");
out.println("document.attach.CatId.value=xxx;");
out.println("document.attach.action=\"../servlet/del_files\";");
out.println("document.attach.submit();")
out.println("}");
out.println("}");
out.println("}");

Thanks..
View Answers

July 15, 2010 at 4:01 PM

Hi Friend,

Try the following code:

1)Servlet.java:

import java.io.*;
import java.sql.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class Servlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)throws IOException, ServletException{
PrintWriter out = response.getWriter();
out.println("<html><head><script>function deleteRecord(id){var r=confirm('Are you confirm')");
out.println("if (r==true){var reason=prompt('Reason for deleting:')");
out.println("window.open('http://localhost:8080/examples/modified/deleteuser.jsp?id='+id+'&&reas='+reason,'mywindow','width=500, height=350,toolbar=no,resizable=yes,menubar=yes')");
out.println("}}</script></head>");
out.println("<form name='form'>");
out.println("<table border='1'>");
out.println("<tr><th>FirstName</th><th>LastName</th><th>Address</th><th>Email</th></tr>");
Connection con = null;
String url = "jdbc:mysql://localhost:3306/";;
String db = "test";
String driver = "com.mysql.jdbc.Driver";
String userName ="root";
String password="root";
int sumcount=0;
Statement st;
try{
Class.forName(driver).newInstance();
con = DriverManager.getConnection(url+db,userName,password);
String query = "select * from employee";
st = con.createStatement();
ResultSet rs = st.executeQuery(query);
while(rs.next()){
out.println("<tr><td>"+rs.getString(2)+"</td><td>"+rs.getString(3)+"</td><td>"+rs.getString(4)+"</td><td>"+rs.getString(5)+"</td>");
out.println("<td><input type='button' name='edit' value='Delete' style='background-color:red;font-weight:bold;color:#ffffff;' onclick=\"deleteRecord('"+rs.getString(1)+"');\"></td></tr>");
}
}
catch (Exception e) {
e.printStackTrace();
}
out.println("</table>");
out.println("<form>");
out.println("</html>");
}
}

2)deleteuser.jsp:

<%@page language="java"%>
<%@page import="java.sql.*"%>
<%
String reason=request.getParameter("reas");
out.println("Reason is: "+reason);
String id=request.getParameter("id");
int no=Integer.parseInt(id);
int sumcount=0;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test";, "root", "root");
Statement st = conn.createStatement();
st.executeUpdate("DELETE FROM employee WHERE userid = '"+no+"'");
out.println("<br>Record is deleted successfully");
}
catch(Exception e){}
%>

Hope that it will be helpful for you.
Thanks









Related Tutorials/Questions & Answers:
javascript for textbox or prompt using servlet - JSP-Servlet
javascript for textbox or prompt using servlet  Dear sir I am writing script in servlet,so prompt() is not working here so please help me... ,if they are confirmed to delete the i have to take a reason for deleting a textbox as to come
javascript for textbox or prompt using servlet - JSP-Servlet
javascript for textbox or prompt using servlet  Dear sir, I am using a prompt(),when a delete is confirmed,its working fine ,but when a prompt is closed or cancel ,i have to remain in the same page but here it is going
Advertisements
javascript for prompt - JSP-Servlet
javascript for prompt  Dear sir, I have used prompt() for taking a reason while deleting using java script its working fine but prompt was coming at the top left so i want that prompt should come at middle so how to do
javascript for prompt - JSP-Servlet
javascript for prompt  Dear Sir, I am using a prompt() for taking... a prompt contains any special character or what.If contains a alert message has... then that prompt was not coming..So please tel me how to validate a prompt
javascript for prompt - JSP-Servlet
javascript for prompt  Dear sir, I am using prompt()for taking a reason from vendor . var reason=prompt('Reason for deleting:',''); Then i... an object ,so how to remove this script error.And also this prompt is coming
javascript for textbox - JSP-Servlet
javascript for textbox  Dear sir , How to write a javascript for a textbox ?.I am doing a delet operation.When i clik on a particular record... a javascript to do so ..Please help me sir... Thanks...  Hi Friend, Try
javascript for textbox - JSP-Servlet
javascript for textbox  Dear Sir, In my project if i use a var reason=prompt(\"Reason for deleting:\",\"\") in a javascript after confirm the delete option ,its not invoking the prompt()...So please help me.. Thanks
javascript for textbox - JSP-Servlet
javascript for textbox  Dear Sir , Thanks for posting an answer, its working fine .Sir how to get the text what we have entered in a prompt(reason... that value.I used the following code reason=prompt("Reason for deleting
javascript for textbox - JSP-Servlet
javascript for textbox  Dear sir, Thanks for your post,but when i write if(reason=="") i am getting a following error in eclipse i.e a red... written if(reason=="") in Scriptlets?You can write this code only in the javascript
How to check text in textbox using JavaScript
How to check text in textbox using JavaScript  How to check text in textbox using JavaScript I have a form in HTML that contains text feilds... me.   JavaScript validation example to check text in textfeild <
javascript prompt alert
javascript prompt alert   Sending a prompt alert using a JavaScript function
using prompt
using prompt  how to use prompt
prompt using
prompt using  I want examples to use prompt and how to move the item from the prompt to a cell in a table. thank you
Javascript generate textbox
Javascript generate textbox In this tutorial, you will learn how to generate a textbox on button click using javascript. Here is a javascript example... of textboxes. On clicking the button with respect to each textbox, it will give
passing textbox value from one page to another page using html n javascript
passing textbox value from one page to another page using html n... of variable at onclick event of button and also want to print it in textbox...)page2.html: <html> <script LANGUAGE="JavaScript"> function getParams
coding for horizontal menubar using using html or javascript - JSP-Servlet
coding for horizontal menubar using using html or javascript  hii friends, i wanted to implement horizontal menubar in my project tht wil open the links to diffrnt pages kindly help
Prompt
into methods in the method asking for the input it uses a prompt command...) { System.out.print(**prompt** + ' '); return numberOfGrades } I don't undersant the prompt part
javascript error in IE - JSP-Servlet
javascript error in IE  Please Help me, I have an urgent requirement i.e. JavaScript prompt box is not working in IE. It Works firefox,safari... in the Internet Options->customlevel changes. How to do displayin the prompt box using
how to get data using dropdownlist, textbox and search button in jsp
how to get data using dropdownlist, textbox and search button in jsp  Hi, I want to display data using jsp,javascript and mysql. My Q. is If i select...' in textbox and click on search button it should show me all the title names
delete an entry using JavaScript
delete an entry using JavaScript  How to delete an entry using JavaScript
Date object using JavaScript
Date object using JavaScript  What's the Date object using JavaScript
using for loop in javascript
using for loop in javascript  How to use for loop in JavaScript
maximize an image using javaScript
maximize an image using javaScript  Write the code to maximize an image using javaScript
xls to js using javascript
xls to js using javascript  ![how can we convert a xls file in js file using javascript][1
timer using javascript
timer using javascript  How to display timer on HTML page using JavaScript
Javascript change textbox background
Javascript change textbox background In this section, you will learn how to change the background of textbox. Here we have created a textbox and allowed the user to enter the valid name. If the entered name is 'roseindia
Set Textbox in PowerPoint Slide Using Java
Set Textbox in PowerPoint Slide Using Java       In this example we are going create textbox to set text in PowerPoint using java. In this example we are creating an object of 
How to create textbox on combo value selection using javacsript in jsp?
How to create textbox on combo value selection using javacsript in jsp?  dynamically create textbox on combo value selection. when select multiple values then create multiple textboxes
send mail using JavaScript
send mail using JavaScript  How can we send mail using JavaScript?   Hi friends, You can not send email directly using JavaScript. But you can use JavaScript to execute a client side email program send the email using
javascript - JSP-Servlet
javascript  how to convert a string to long in javascript
javascript - JSP-Servlet
javascript  using below code i got value in textbox but i also wants to use this textbox value in query in same page.. function passVariable(){ var v=document.form.txt.value; document.form.txt1.value=v; } Enter
How to display on textbox using ObjectUtil class
How to display on textbox using ObjectUtil class       In this tutorial we will see how to display a text in textbox using ObjectUtil class. Here
calling java method from html form with out using javascript - JSP-Servlet
calling java method from html form with out using javascript  How can i call java method from a HTML form, java script should be disabled?  Hi <html><head><title>Test Input Validation</title><
javascript - JSP-Servlet
Disabled JavaScript on Browser  How can i disabled JavaScript for a particular browser
Getting data from servlet into javascript
Getting data from servlet into javascript  How do i get json data from my servlet on to a variable in javascript n bind the data to display onto sigma grid.Has anyone Idea how to do
Selecting value from autocomplete textbox using jquery in jsp
Selecting value from autocomplete textbox using jquery in jsp   hello Sir, I completed ur tutorial on autocompletion textbox from database using... not select the suggested values in the textbox,means on clicking particular field
How to insert dynamic textbox values into database using Java?
How to insert dynamic textbox values into database using Java?  Hi I am trying to insert dynamic textbox values to database, my jsp form have 2... these dynamic textbox values to database(Oracle 11g)...Please help me out. I have
Video Tutorial: How to create a database in MySQL using Command prompt?
How to create a database in MySQL using Command prompt MySQL is an Operation... is the video tutorial of "How to create database in MySQL using command prompt... in MySQL using command prompt. To create a database we need to use
How to shift and unshift using JavaScript?
How to shift and unshift using JavaScript?  How to shift and unshift using JavaScript
populating textbox value from the database using onchange function,
populating textbox value from the database using onchange function,  hi, Everyone I have a problem regarding poulatinng the value in textbox after.... but the next textbox value is populated from database. plz help me guys
javascript date validation using regex
javascript date validation using regex  Hi, I want to validate the date using javascript. Please help.   <html> <head> <title>Validating Date format</title> <script type="text/javascript">
Call servlet from javascript - JSP-Servlet
Call servlet from javascript  Hi in my application i have jsp that designs view, javascript for validation and servlet that perform business logic... the read column values present in grid and pass it to servlet along with url
select value from autocomplete textbox using jquery in jsp from database.
select value from autocomplete textbox using jquery in jsp from database.  Hii Sir, Lots of thnx to ur reply .I went through both... of selecting value from autocomplete textbox using jquery in jsp from mysql database
select value from autocomplete textbox using jquery in jsp from database.
select value from autocomplete textbox using jquery in jsp from database.  Sir, Lots of thnx to ur reply .I went through both the tutorials... autocomplete textbox using jquery in jsp from mysql database. Kindly send me
javascript Code - JSP-Servlet
javascript Code  how to count controls in form and find no of contriols in html or jsp page.for example one table is there with 10 rows,each row consists of 3 fields as 2 text box and one drop down box
javascript-html - JSP-Servlet
javascript-html  i want to dynamically create textfield with option button as another/remove when user presses in jsp page which will be in table.for example table contains one row with 2 columns,one textfield,second dropdown
How to insert data from a combobox and textbox values into DB using JSP?
How to insert data from a combobox and textbox values into DB using JSP?  hi, How to insert a comb-box and a text box values in to DB using JSP? @DB:student; @table:stu_info; Combobox values:(class1,class2,class3); textbox1
javascript-html - JSP-Servlet
javascript-html  i want to dynamically create textfield with option button as another/remove when user presses in jsp page which will be in table.for example table contains one row with 2 columns,one textfield,second dropdown
Solve using only Javascript loops...
Solve using only Javascript loops...  Write a JavaScript code, 1... of the week. 4) that reads the date of a day in one textbox, the month in a second textbox and the year in a third textbox. After submitting the form, it should
javascript - JSP-Servlet
javascript  i dont have the jsp code . using simple jsp file and without using alert message box.i need using of getElementByID

Ads