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:
Advertisements
javascript for prompt - JSP-Servletjavascript 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-Servletjavascript 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-Servletjavascript 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-Servletjavascript 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-Servletjavascript 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-Servletjavascript 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-Servletjavascript 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 JavaScriptHow 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
<
prompt usingprompt 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 textboxJavascript 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
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-Servletjavascript 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 Javascript change textbox backgroundJavascript 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
send mail using JavaScriptsend 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-Servletjavascript
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
Getting data from servlet into javascriptGetting 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
javascript date validation using regexjavascript 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-ServletCall
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
javascript Code - JSP-Servletjavascript 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-Servletjavascript-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
javascript-html - JSP-Servletjavascript-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-Servletjavascript i dont have the jsp code .
using simple jsp file and without
using alert message box.i need
using of getElementByID