Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: how to insert in a different jsp website?

  1. #1
    Junior Member
    Join Date
    Jan 2014
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default how to insert in a different jsp website?

    my problem is i have an error in my problem.jsp the id first name email last name etc will be entered in one page reg.jsp. the problem column will be entered on the contact.jsp page. how do you do this? check my code below

    to start, i have created a database:

    CREATE TABLE `members` (
      `id` int(10) unsigned NOT NULL auto_increment,
      `first_name` varchar(45) NOT NULL,
      `last_name` varchar(45) NOT NULL,
      `email` varchar(45) NOT NULL,
      `uname` varchar(45) NOT NULL,
      `pass` varchar(45) NOT NULL,
      `regdate` date NOT NULL,
       problem char(250) NOT NULL
      PRIMARY KEY  (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;

    the id,first name, last name, email, uname, pass, regdate can be inserted here:

    reg.jsp

    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <!DOCTYPE html>
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>REGISTRATION</title>
        </head>
        <body bgcolor="#BDBDBD">
            <form method="post" action="registration.jsp">
                <center>
                <table border="1" width="30%" cellpadding="5">
                    <thead>
                        <tr>
                            <th colspan="2">Enter Information Here</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>First Name</td>
                            <td><input type="text" name="fname" value="" /></td>
                        </tr>
                        <tr>
                            <td>Last Name</td>
                            <td><input type="text" name="lname" value="" /></td>
                        </tr>
                        <tr>
                            <td>Email</td>
                            <td><input type="text" name="email" value="" /></td>
                        </tr>
                        <tr>
                            <td>User Name</td>
                            <td><input type="text" name="uname" value="" /></td>
                        </tr>
                        <tr>
                            <td>Password</td>
                            <td><input type="password" name="pass" value="" /></td>
                        </tr>
                        <tr>
                            <td><input type="submit" value="Submit" /></td>
                            <td><input type="reset" value="Reset" /></td>
                        </tr>
                        <tr>
                            <td colspan="2">Already registered!! <a href="index.jsp">Login Here</a></td>
                        </tr>
                    </tbody>
                </table>
                </center>
            </form>
        </body>
    </html>

    registration.jsp

    <%@ page import ="java.sql.*" %>
    <%
        String user = request.getParameter("uname");    
        String pwd = request.getParameter("pass");
        String fname = request.getParameter("fname");
        String lname = request.getParameter("lname");
        String email = request.getParameter("email");
        Class.forName("com.mysql.jdbc.Driver");
        Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/users",
                "root", "");
        Statement st = con.createStatement();
        ResultSet rs;
        int i = st.executeUpdate("insert into members(first_name, last_name, email, uname, pass, regdate) values ('" + fname + "','" + lname + "','" + email + "','" + user + "','" + pwd + "', CURDATE())");
        if (i > 0) {
            //session.setAttribute("userid", user);
            response.sendRedirect("welcome.jsp");
           // out.print("Registration Successfull!"+"<a href='index.jsp'>Go to Login</a>");
        } else {
            response.sendRedirect("index.jsp");
        }
    %>


    and my problem column can be enter here:

    contact.jsp

     <title>CONTACT US</title>
    <body bgcolor="#BDBDBD">
     
    <table border=1 align="center"<tr><td>
    <%
        if ((session.getAttribute("userid") == null) || (session.getAttribute("userid") == "")) {
    %>
    You are not logged in<br/>
    <a href="index.jsp">Please Login</a>
    <%} else {
    %>
    <form method="post" action="problem.jsp">
    <%=session.getAttribute("userid")%><br />
    </tr></td><tr><td>
    Have a question for us?</tr></td><tr><td>
    Enter your question here(250):</tr></td><tr><td>
    <textarea rows="4" cols="50"></textarea></tr></td>
    <tr><td>EMAIL
    <input type="text" name="email" id="email" />
    </tr></td>
    <tr><td>
    <input type="submit" value="Login" />
    </tr></td>
    </table>
    </form>
    <%
        }
    %>
    </body>

    and in here. here is my problem i dont really know how to do this. i want to enter a question and the question i enter will be saved to the problem column. here is my code:

    problem.jsp

    <%@page import="java.sql.*"%>
    <%@page import="java.io.*"%>
    <%
    String prob = request.getParameter("problem");
     
     
       Class.forName("com.mysql.jdbc.Driver");
        Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/users",
                "root", "");
        Statement st = con.createStatement();
        ResultSet rs;
        int i = st.executeUpdate("insert into members(first_name, last_name, email, uname, pass, regdate, problem) values ('" + fname + "','" + lname + "','" + email + "','" + user + "','" + pwd + "', CURDATE(),'" + prob +"'");
        if (i > 0) {
            //session.setAttribute("userid", user);
            response.sendRedirect("welcome.jsp");
           // out.print("Registration Successfull!"+"<a href='index.jsp'>Go to Login</a>");
        } else {
            response.sendRedirect("index.jsp");
        }
    %>


  2. #2
    Member Ganeprog's Avatar
    Join Date
    Jan 2014
    Location
    Chennai,India
    Posts
    80
    My Mood
    Love
    Thanks
    3
    Thanked 6 Times in 6 Posts

    Default Re: how to insert in a different jsp website?

    Hi,

    In my point of view, don't do insertion in "problem" column. Use update query you can update the problem column based on the "userid"

    Thanks,

Similar Threads

  1. How to insert data in MYSQL with jsp
    By blasic in forum JDBC & Databases
    Replies: 3
    Last Post: December 5th, 2013, 01:03 PM
  2. Jsp Servlet problem with getting parameter vaules from another jsp page
    By venkat_tk in forum JavaServer Pages: JSP & JSTL
    Replies: 0
    Last Post: February 25th, 2013, 02:51 AM
  3. Parent JSP Page is not refreshing properly after modifying a child Jsp.
    By jay_84 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 14th, 2011, 09:59 AM
  4. saving the data of the child jsp into parent jsp
    By nrao in forum JavaServer Pages: JSP & JSTL
    Replies: 0
    Last Post: January 15th, 2011, 11:05 AM
  5. Replies: 1
    Last Post: January 15th, 2010, 01:32 AM

Tags for this Thread