I am new to ember.I am using ember-cli,I want to push my data to the mysql database i have written the backend code in jsp.My jsp file is working well without ember. This is my code.
app/controller/new-user.js
import Ember from 'ember';
export default Ember.Controller.extend({
actions:{
register:function(){
var fname=this.get('fname');
var lname=this.get('lname');
var email=this.get('email');
var password=this.get('password');
var confirmPassword=this.get('confirmPassword');
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (xhttp.readyState === 4 && xhttp.status === 200) {
var txt=xhttp.responseText;
document.write(txt);
}
};
xhttp.open("GET", "process1.jsp?fname="+fname+"&lname="+lname+"&email="+email+"&password="+password+"&confirmPassword="+confirmPassword, true);
xhttp.send();
}
}
});
public/process1.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@page import="java.sql.*"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<%
String fname=request.getParameter("fname");
String lname=request.getParameter("lname");
String email=request.getParameter("email");
String password=request.getParameter("password");
String confirmPassword=request.getParameter("confirmPassword");
Connection con = null;
try{
Class.forName("com.mysql.jdbc.Driver");
con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/lahari", "root", "bhavya");
Statement st=con.createStatement();
int i=st.executeUpdate("insert into users(fname,lname,email,password,confirmPassword) values('"+fname+"','"+lname+"','"+email+"','"+password+"','"+confirmPassword+"')");
if(i==1){
response.sendRedirect("one.txt");
}
else{
out.println("errorr");
}
}
catch(Exception e){
System.out.print(e);
e.printStackTrace();
}
%>
</body>
</html>
public/one.txt
you are registered
No records are inserted to my mysql database.I also kept mysql connector in my public folder.Anyone can please tell me what is wrong in the code?.
Aucun commentaire:
Enregistrer un commentaire