Sie sind auf Seite 1von 4

fouzia <html> <head> <title>Some Math</title> <% public static int fibo(int n) { if (n <= 2) return 1; else return fibo(n

- 1) + fibo(n - 2); }

%> </head> <body> <% for (int i = 1; i <= n; i++) { int f = fibo(i); System.out.print(f +" "); } %> </body> </html>

Enter.html <html> <head> <title>New Page 1</title> </head> <body> <form method="GET" action="/htmlform/MathServlet"> Enter number <input type="text" name="no" > <input type="submit" value="Submit" name="B1"> </form> </body> </html>

MathServlet.java : import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class MathServlet extends HttpServlet{ public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); <% String num = request.getParameter("no"); double number = Double.parseDouble(num); %> <% double sqrt = Math.sqrt(number); Double cbr = Math.cbrt(number); %> <p>Square Root of <%= number %> is <%= sqrt %> .</p> <p>Cube Root of <%= number %> is <%= cbr %> .</p>

import java.awt.*; import java.awt.event.*; import java.sql.*; import javax.swing.*; public class Test1 extends JFrame implements ActionListener { Container c; JFrame f; JLabel l1,l2,l3,l4; JButton btn1,btn2; JTextField t1,t2,t3,t4; Connection con=null; ResultSet rs=null; Statement st=null; Test1() { f=new JFrame("Demo"); c=f.getContentPane(); c.setLayout(new FlowLayout()); f.setVisible(true); f.setSize(500,500); l1=new JLabel("First name"); l2=new JLabel("last name"); l3=new JLabel("Password"); l4=new JLabel("Confirm password"); t1=new JTextField(20); t2=new JTextField(20); t3=new JTextField(20); t4=new JTextField(20); btn1=new JButton("SUBMIT"); btn2=new JButton("CLEAR"); f.add(l1); f.add(t1); f.add(l2); f.add(t2); f.add(l3); f.add(t3); f.add(l4); f.add(t4); f.add(btn1); f.add(btn2); btn1.addActionListener(this); btn2.addActionListener(this); } public void actionPerformed(ActionEvent ae)

{ if(ae.getActionCommand()=="SUBMIT") { String fname,lname,pass,confp; fname=t1.getText(); lname=t2.getText(); pass=t3.getText(); confp=t4.getText(); try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); con =DriverManager.getConnection("jdbc:odbc:aaa"); st=con.createStatement(); rs = st.executeQuery("Insert Into Login (firstname,lastname,password,confirmpassword)Values('"+fname+"','"+lname+"','"pass+"','"+confp+"')") ; con.close(); } catch(Exception e){ } } else{ t1.setText(" "); t2.setText(" "); t3.setText(" "); t4.setText(" "); } public static void main(String[] args) { Test1 t=new Test1(); } }

Das könnte Ihnen auch gefallen