jsp and java

jsp and java

how to write a jsp and related java code to enter student marks into database

View Answers

February 4, 2011 at 12:15 PM

Hi Friend,

Try the following code:

1)insert.jsp:

<%@page import="java.sql.*"%>
<html>
<form method="post" action="../InsertServlet">
<table>
<tr><td>Name:</td><td><input type="text" name="name"></td></tr>
<tr><td>Marks:</td><td><input type="text" name="marks"></td></tr>
<tr><td></td><td><input type="submit" value="Submit"></td></tr>
</table>
</form>
</html>

2)InsertServlet.java:

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

public class InsertServlet extends HttpServlet { 
    public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException {
        res.setContentType("text/html");
        PrintWriter out = res.getWriter();
        String name=req.getParameter("name");
        String marks=req.getParameter("marks");
        int mm=Integer.parseInt(marks);
try{
Class.forName("com.mysql.jdbc.Driver");
           Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
           Statement st=con.createStatement();
           int i=st.executeUpdate("insert into student(name,marks) values('"+name+"',"+mm+")");
         out.println("Data is inserted successfully");
         con.close();
        }
catch(Exception e){
    System.out.println(e);
}
            }
        }

Thanks









Related Tutorials/Questions & Answers:
Java jsp
Java jsp  What is JSP
jsp and java
jsp and java  how to write a jsp and related java code to enter student marks into database
Advertisements
java jsp - JSP-Servlet
java jsp  i have a jsp file, in that i am uploading a file, after uploading the file had to display in the screen. it is displaying if only i refresh the page. but i want to display the uploaded file without refreshing the page
java - jsp
java - jsp  program to view and update employee name using JSP without database
JSP with java/servlet - JSP-Servlet
JSP with java/servlet  Thanks Deepak for your answere to my previous question. With reference to my previous question about JSP populate, actually I... (java bean or servlet) to fecth the database. Jsp would get the data from
Java from JSP - JSP-Servlet
Calling Java from JSP  Does anyone have an example of Calling Java from JSP
multiuser in java/jsp? - JSP-Servlet
multiuser in java/jsp?  Hi!!! Rose India Team, Kindly let me know what is exact meaning of multiuser in java? I made an web application using jsp... friend, Multi User in Jsp : More then one User can access in Web appication
java/jsp
java/jsp  In a JSP program called books.jsp, the Java code out.print(request.getParameter(ā??numberā??)); displays "1111111ā??. What are the possible ways for the parameter number to have got its value
JAVA JSP and Servlet - JSP-Servlet
JAVA JSP and Servlet  for sending mail through lan without intenet and also chatting facility for online users using Java JSP & SERVLET code.  Hi Friend, Please visit the following links: http://www.roseindia.net
Java or Jsp code - JSP-Servlet
Java or Jsp code  Hello Sir, How to create the code for the password recovery page(like forgot gmail password question and answer page)using the radion buttons in display the same page in jsp.I need only how to make
JAVA,JSP,SERVELTS
JAVA,JSP,SERVELTS  plz Send me Login Page by using core java ,Jsp,Servelts
java - JSP-Servlet
java  why is required to write both jsp and servlet in a application of java
java jsp
java jsp  please I want code to parse a web page using Dom parser, thanks
java jsp
java jsp  it is : javax.servlet.jsp only but getting error wt is reason?   Use javax.servlet.jsp.* in your code
Jsp count and java bean - JSP-Servlet
Jsp count and java bean  Please am on a project and i want to create a countdown timer that will have this format HH:MM:SS. Am working with jsp and java beans please somebody help.  Hi Friend, Try the following
how to call a java class in jsp - JSP-Servlet
how to call a java class in jsp  hi.. friends iam new to roseindia.i found it very nice site to clarify our douts. i have a problem to use my java... : Example of Extends Attribute of page Directive in JSP
how to call a java class in jsp - JSP-Servlet
how to call a java class in jsp  hi.. friends iam new to roseindia.i found it very nice site to clarify our douts. i have a problem to use my java... : Example of Extends Attribute of page Directive in JSP
Java JSP - JDBC
Java JSP  JDBC connectivity in JSP?  Hi Friend, Please visit the following link: http://www.roseindia.net/jsp/Accessingdatabase-fromJSP.shtml Hope that it will be helpful for you. Thanks
java-script,jsp - JSP-Servlet
java-script,jsp   how can i shift to other page when my timer shows t<=0 .i.e timeout?   Hi Friend, Try the following code: timer.jsp: var time = null function go() { window.location = 'form.jsp
java,servlet,jsp - JSP-Servlet
java,servlet,jsp   i am doing a project on online examination system and in that there are problems that-- 1.i want to disable the back,forward and refresh button.Please give me the code for google crome browser. 2.suppose
JSP
JSP  Hi, What is JSP? What is the use of JSP? Thanks   Hi, JSP Stands for Java Server Pages. It is Java technology for developing web applications. JSP is very easy to learn and it allows the developers to use Java
A Java Program by using JSP
A Java Program by using JSP  how to draw lines by using JSP plz show me the solution by using program
java (servlet) - JSP-Servlet
java (servlet)  how can i disable back button in brower while using servlet or JSP
jsp code - Java Beginners
JSP code and Example  JSP Code Example
jsp - Java Beginners
currently logged in, using jsp and java bean mysql as back end. urgent reply pls ... visit for more information. http://www.roseindia.net/jsp/ http://www.roseindia.net/jsp/loginbean.shtml http://www.roseindia.net/jsp/loginstatus.shtml
java bar charts and jsp
java bar charts and jsp  Hi, Can any one help me out in how to create java bar charts using jsp with the help of data base table values? thanks.../jsp/draw-statistical-chart-jsp.shtml
Java - JSP-Servlet
Java  Dear Deepak, In my Project we need to integrate Outlook Express mailing system with java/jsp. thanks & regards, vijayababu.m
java - JSP-Servlet
java   can anyone help me with an idea to develop whiteboard using jsp. it is very important for me. Thank you. Ram
Java Code - JSP-Servlet
Java Code  Write a JSP program which displays a webpage containg arrival of new items within a particular month in the different branches of a retail company
java charts - JSP-Servlet
java charts  Hi,can any one tell me how to create dyanamic charts wrt database contents by using jsp-servlet
Java - JSP-Servlet
Java, JSP vs Servlet  If anyone have idea about how to use all these technologies in one project ..please share with me. Thanks
JSP - Java Beginners
JSP  sir, how to use in core jave code?This is not servlet.how to redirect from core java to servlet or jsp or html file
java - JSP-Interview Questions
java  hi.. snd some JSP interview Q&A and i wnt the JNI(Java Native Interface) concepts matrial thanks krishna  Hi friend, Read more information. http://www.roseindia.net/interviewquestions/jsp-interview
java script - JSP-Servlet
java script  hello buddy......i m new to here....please help me to solve my problem i have a jsp page with pre populated value comming from other jsp.....ones i submitted i have to clear that page and i have to submite
Java Problem - JSP-Servlet
Java Problem  How to run a Simple JSP program ? what steps... the webapps folder of apache tomcat. 5)Create a jsp file 'hello.jsp'.You can put your jsp file either inside the web application folder along with WEB-INF or you
java servet +jsp+mysqldatabase
java servet +jsp+mysqldatabase  I created three servlets(based on title, bookname, author) and one jsp page. in jsp page i put one dropdown list box(that is title, author, bookname) and created mysql database column values
how to include a java class in jsp - JSP-Servlet
how to include a java class in jsp  hello sir, this is my first question, i want know that how to use a java class function's variables and methods of a java class in jsp.if possible plz tr to explain with a simple example
JSP to output Java String Array - JSP-Servlet
JSP to output Java String Array  I am just a little confused about the output that I would get from printing a 2D String array loaded with database fields. For example lets say we have the following array: String [ ][ ] array
JSP - Java Server Pages
JSP JSP stands for Java Server Pages. JSP is Java technologies for creating dynamic web applications. JSP allows the developer to embed Java code inside HTML. It makes the development of dynamic web application very easy in Java
java/jsp code to download a video
java/jsp code to download a video  how can i download a video using jsp/servlet
Display Java in JSP
Display Java in JSP  please i need urgent help. How can i display Java Applet created in netbeans in JSP?. the Application involves MYSQL Database connection. Thanks
java and oracle - JSP-Servlet
java and oracle  I am developing a small project where I need to upload the resume of the employee and store it into database and retrieve the same... and jsp
Java - JSP-Servlet
Java  Hi All, How to integrate Outlook Express with java/jsp. Plase any one help me. thanks®ards, vijayababu.m  Hi Friend, Use the following: Send Mail Thanks
jsp
jsp  how to assign javascript varible to java method in jsp without using servlet
jsp - Java Interview Questions
What is Java JSP and Java Servlet  What is JSP? and ..What is Servlet in Java?  jsp: separate the prsentation and business logic.(custom.... * Abbreviation for JSP is Java Server Pages. That is java code can
JSP - Java Beginners
JSP  Hai friends, I want to use the flash image on jsp or java script, if i click the image then it goes to the next page...... If any one... the following link: http://www.roseindia.net/jsp/add-flash-jsp.shtml Hope
Converting jsp variable to java variable
Converting jsp variable to java variable  Hi how to convert java script variable to java variable on same jsp page
Creating dynamic jsp file in java file to include another jsp file
Creating dynamic jsp file in java file to include another jsp file  I am able to create jsp file in java that includes ; table tr td and img tags..... Need to include jsp file in the same content. The below code doesn't help me
jsp - Java Beginners
JSP exception handling tags   What are the JSP exception handling tags
Jsp - Java Interview Questions
Need JSP Interview Questions  Hi, I need JSP interview questions.Thanks

Ads