Question: j2ee

Ads

 
 
 

Share on Google+Share on Google+

muniraju
j2ee
1 Answer(s)      6 years ago
Posted in : Java Beginners
hi i'm beginner 2 j2ee.. my question is...

(jdbc connecton):
when user enters his fname,lname,address,city from ui(html) it gets inserted into db...my problem is when user submit without entering i,e blank it also get inserted into db even though i have given not null for each elements in database table..so when user enters nothing it should not get inserted into db and should return to home page ...can any one help me ????
Ads
View Answers

May 6, 2011 at 3:38 PM


Use javascript.

Here is the code:

1)register.html:

<html>
<script>

function validate(){

    if(document.form.fname.value == ""){
        alert( "Please enter first name." );
        document.form.fname.focus();
        return false;
    }
     if(document.form.lname.value == ""){
        alert( "Please enter last name." );
        document.form.lname.focus();
        return false;
    }

    if(document.form.address.value == ""){
        alert( "Please enter address." );
        document.form.address.focus();
        return false;
    }


     if(document.form.city.value == ""){
        alert( "Please enter city." );
        document.form.city.focus();
        return false;
    }


        return true;

   }  
</script>
<form name="form" method="post" onsubmit="return validate();" action="http://localhost:8080/examples/jsp/insertdata.jsp">
<table>
<tr><td>Enter First Name</td><td><input type="text" name="fname"></td></tr>
<tr><td>Enter Last Name</td><td><input type="text" name="lname"></td></tr>
<tr><td>Enter Address</td><td><input type="text" name="address"></td></tr>
<tr><td>Enter City</td><td><input type="text" name="city"></td></tr>
<tr><td></td><td><input type="submit" value="Add" name="button"></td></tr>
</table>
</form>
</html>

2)insertdata.jsp:

<[email protected] import="java.sql.*,java.util.*"%>
<%
String fname=request.getParameter("fname");
String lname=request.getParameter("lname");
String address=request.getParameter("address");
String city=request.getParameter("city");

        try{
         Class.forName("com.mysql.jdbc.Driver");
           Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/roseindia", "root", "root");
           Statement st=con.createStatement();
        int i=st.executeUpdate("insert into student(firstname,lastname,address,city) values('"+fname+"','"+lname+"','"+address+"','"+city+"')");
        out.println("Data is successfully inserted into database.");
          }
        catch(Exception e){
        System.out.println(e);
        }
        %>

Ads









Related Tutorials/Questions & Answers:
j2ee
j2ee  what is j2ee
j2ee
j2ee  sir can you give me some of the definitions of project under the platform of j2ee
Advertisements
J2EE
J2EE  what is single table strategy in JPA
J2EE
J2EE  What is J2EE?   J2EE is an environment for developing and deploying enterprise applications. The J2EE platform consists of a set of services, application programming interfaces (APIs), and protocols that provide
j2ee
j2ee  I want program for login page with database connectivity using struts framework. that application should session management and cookies
j2ee
j2ee  I want program for login page with database connectivity using struts framework. that application should session management and cookies
j2ee
j2ee  hi i'm beginner 2 j2ee.. my question is... when user enters his fname,lname,address,city from ui(html) it gets inserted into db...my problem is when user submit without entering i,e blank it also get inserted into db even
j2ee
j2ee  hi i'm beginner 2 j2ee.. my question is... when user enters his fname,lname,address,city from ui(html) it gets inserted into db...my problem is when user submit without entering i,e blank it also get inserted into db even
j2ee
j2ee  hi i'm beginner 2 j2ee.. my question is... (jdbc connecton): when user enters his fname,lname,address,city from ui(html) it gets inserted into db...my problem is when user submit without entering i,e blank it also get
J2EE - JMS
J2EE  hai,This is jagadhish.Iam learning J2EE. I want to know the concept JMS.For that send some data and example programs plz.thank you (in advance
J2EE clients
J2EE clients  What are types of J2EE clients?   Following are the types of J2EE clients: Applets. Application clients. Java Web Start-enabled rich clients, powered by Java Web Start technology. Wireless clients, based
j2ee - Struts
j2ee  hi can you explain what is proxy interface in delegater design pattern
j2ee - EJB
j2ee  when we given a request for ejb cointainer how the container calls the we requested method call
j2ee - Hibernate
j2ee  what is meant by o-r mapping with an example what is the difference between bean,javabean,ejb with an example
J2EE - Struts
J2EE  what is Struts Architecture?  Hi Friend, Please visit the following links: http://www.roseindia.net/struts/StrutsArchitecture.shtml http://www.roseindia.net/struts/struts2/struts-2-architecture.shtml
J2EE Application
J2EE Application  I developed a j2ee application.I used apache tomcat server on my machine and ran it using http://<IPaddressOfMachine>(OR)localhost:8080/<ApplicationName> Its running on my machine fine as well
j2ee - Struts
j2ee  How to get values from a database which is stored in form1 in to form2 with in a listbox. pls help me.  Hi bhaskar, You have to write database related code in the form itself in which the list box is present
j2ee - Spring
j2ee  hi guys can any send me the spring mvc example,thanks in advance  Hi Friend, Please visit the following link: http://www.roseindia.net/spring/index.shtml Hope that it will be helpful for you. Thanks
j2ee - JDBC
J2EE - Counting the number of records in the table  Counting the number of records in the table J2EE  Hi,Are you trying to find the solution for counting the number of records in the table.Suppose you have student table
J2EE - Date Calendar
J2EE Server List  j2ee server list
j2ee - JDBC
j2ee  how to connect jsp to mysql   Hi, Thanks for asking question. I will tell you how you can connection to MySQL from JSP page. Actually you have to install the MySQL driver in your web application
j2ee - EJB
j2ee  how can u make a call from session Bean of SessionFacade to Entity Bean when ur using persistence logic implemented in Entity Beans. I think inorder to get the home interface obj for first time it will look up in jndi
J2ee - Hibernate
J2ee  I need to save datas like employee details in database, while saving i am getting exceptioin as org.hibernate.exception.GenericJDBCException: caused by com.microsoft.sqlserver.jdbc.SQLServerException: and an error
j2ee - EJB
j2ee  i want to know the ejb 2.0 architecture by diagram and also ejb 3.0 architecture i want to know the flow in ejb 2.0 and ejb 3.0  Hi friend, I am sending you a link. This link will help you. Please visit
j2ee - JDBC
j2ee  import java.sql.*; public class Sample1 { public static void main(String args[])throws Exception { Class.forName("Oracle.jdbc.driver.OracleDriver"); Connection con=DriverManager.getConnection("jdbc:oracle
Components of J2EE application
Components of J2EE application  What are the components of J2EE application
J2EE - Java Beginners
J2EE Programming  What i need to learn to start programming in J2EE
doubt about J2EE connetivity
doubt about J2EE connetivity  steps to connect J2EE components with MYSQL
j2ee - Java Beginners
j2ee  class one
j2ee - JSP-Servlet
j2ee  What is session
j2ee hibernate
In this section you will learn about hibernate for j2ee
Tutorials   
Java Spring Hibernate Struts Training java.lang.NoClassDefFoundError: org/apache/http/client/HttpClient How do I resolve this Java Class not found exception? httpclient java.lang.NoClassDefFoundError Apache Commons ioutils maven dependency Read/Convert an inputStream to a String What is the meaning of Java Platform? Why Java is a platform independent language? What is the benefits of learning Core Java? Which technology should I learn after Java? What is array in java with example? How to Convert ArrayList to Array? How to substring in Java? How to format number in Java? What is instance variable in Java? How to download MySQL JDBC driver? What is Calendar class in Java? Which is the best Java tutorials for beginners? How to rename a file in Java? How to delete file in Java code? How to get day from date in Java using Calendar? How to get day of week in Java? How to calculate Date Difference in Java? How to compare date in Java? How to declare array in Java? How to calculate average of array in Java? What is Array in Java? write a java program to find the summation of all the integers entered on command line Sum of two numbers using command line arguments in Java How to create and use Array in Java? How to pass command line arguments in Java? How to create Applet Hello World? Appending String efficiently in Java How to append String in Java? How to list even numbers between 1 and 100? How to add BigDecimal in Java? What is Abstraction In Java? Which is best Beginners Java Tutorial? What is java.util package? Create list from array in Java Filter collection in Java 8 What is the best way to filter a Java Collection? Easy way to transform Collection to Array? How to convert Collection to Array in Java? What are Basic Java Language Elements? Advanced Java Tutorials in 2017 Java brief history Best Reasons to learn Java Java Example Codes and Tutorials in 2017 How do I read a large file quickly in Java? Is learning Java worthwhile?

Ads

 
Advertisement null

Ads