applet servlet communcation with SSL
Posted: Mar 22, 2002 8:26 AM
Advertisement
I have an applet that gets credit card details from a client and sends it to a server. how do i encrypt this with SSL? Also, how can i get the servlet to send the data to a database? heres my applet code: import javax.swing.*; import javax.swing.border.*; import java.awt.*; import java.awt.event.*; import java.applet.*; import java.io.*; import java.net.*; import java.security.*; public class Test extends JApplet implements ActionListener { JButton button; JPanel panel; JTextField textFirst, textSur, textEmail, textCard, textIssue; JComboBox chooseType, chooseMonth, chooseDate; public void init(){ displayForm(); displayFields(); displayButtons(); } public void displayForm() { try{ UIManager.setLookAndFeel(UIManager. getSystemLookAndFeelClassName()); } catch(Exception e){ } //creates the panel panel = new JPanel(); getContentPane().setLayout(new BorderLayout()); getContentPane().add(panel); Color myColor = new Color(255,255,255); panel.setBackground(myColor); panel.setLayout( null ); } public void displayFields() { JLabel labelFirst = new JLabel("First Name:"); labelFirst.setBounds(50, 40, 100, 20); panel.add(labelFirst); textFirst = new JTextField(); textFirst.setBounds(150, 40, 160, 20); panel.add(textFirst); JLabel labelSur = new JLabel("Surname:"); labelSur.setBounds(50, 70, 100, 20); panel.add(labelSur); textSur = new JTextField(); textSur.setBounds(150, 70, 160, 20); panel.add(textSur); JLabel labelEmail = new JLabel("E mail:"); labelEmail.setBounds(50, 100, 100, 20); panel.add(labelEmail); textEmail = new JTextField(); textEmail.setBounds(150, 100, 160, 20); panel.add(textEmail); JLabel labelType = new JLabel("Card Type:"); labelType.setBounds(50, 130, 100, 20); panel.add(labelType); String[] typeList = { "Please choose one", "American Express", "Mastercard", "Solo", "Switch", "Visa" }; chooseType = new JComboBox(typeList); chooseType.setBounds(150, 130, 160, 20); panel.add(chooseType); JLabel labelCard = new JLabel("Card Number:"); labelCard.setBounds(50, 160, 100, 20); panel.add(labelCard); textCard = new JTextField(); textCard.setBounds(150, 160, 160, 20); panel.add(textCard); JLabel labelIssue = new JLabel("Issue:"); labelIssue.setBounds(50, 190, 100, 20); panel.add(labelIssue); textIssue = new JTextField(); textIssue.setBounds(150, 190, 20, 20); panel.add(textIssue); JLabel labelExpire = new JLabel("Expiry Date:"); labelExpire.setBounds(50, 220, 100, 20); panel.add(labelExpire); String[] monthList = { "Please choose one", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12" }; chooseMonth = new JComboBox(monthList); chooseMonth.setBounds(150, 220, 70, 20); panel.add(chooseMonth); String[] yearList = { "Please choose one", "2006", "2005", "2004", "2003", "2002", "2001" }; chooseDate = new JComboBox(yearList); chooseDate.setBounds(240, 220, 70, 20); panel.add(chooseDate); } //method for creating buttons public void displayButtons(){ //creates and displays the buttons button = new JButton("Submit Payment"); button.addActionListener(this); button.setBounds(150, 260, 160, 20); panel.add(button ); } public void actionPerformed(ActionEvent e) { String name = URLEncoder.encode(textFirst.getText()); String card = URLEncoder.encode((String)chooseType.getSelectedItem()); String servletSpec = "http://localhost:8088/Project/servlet/Servlet"; try { // URL url = new URL(servletSpec + "?name=" + name + "?card=" + card); URL url = new URL(servletSpec + "?name=" + name); getAppletContext().showDocument(url); } catch (MalformedURLException f) { getAppletContext().showStatus("Bad URL"); } } } and here is my servlet code: import javax.servlet.*; import javax.servlet.http.*; //import java.awt.*; //import java.awt.event.*; import java.io.*; import java.net.*; public class Servlet extends HttpServlet { public void doGet (HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<HTML><HEAD><TITLE>" + "Payment Recieved" + "</TITLE></HEAD>"); out.println("<BODY><H3>Your Payment details are, " + request.getParameter("name")); out.println("</H3></BODY></HTML>"); } }