protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String name = request.getParameter("name"); // get param
List<String> list = new ArrayList<String>(); // create list
HttpSession session = request.getSession(); // create a session handler object
// if this is new session , add the param to the list, then set the list as session atr
if(session.isNew()) {
System.out.println("in new session");
// this is a new session , add the param to the new list, then add list to session atr …Run Code Online (Sandbox Code Playgroud) 所有我正在做的是点击按钮时从输入中获取值:
var input = $('#input').val();
var data = {
data : input
};
$.ajax({
type: 'POST',
url: 'index.php',
data: data,
dataType: 'text',
succes: function(response){alert(response);},
error: function(){alert("something went wrong");} });
});
Run Code Online (Sandbox Code Playgroud)
});
我的index.php只是:echo'apple'; ,但是当我点击按钮时,它什么都不做.
考虑以下课程:
class Subject
{
private:
char* name; // I must use char pointers, it's for school.
int grade;
public:
Subject() {
name = NULL;
grade = 0;
}
Subject(char *n, int g) {
name = new char[strlen(n)];
strcpy(name,n);
grade = g;
}
~Subject() {
delete name;
}
void operator=(const Subject &obj) {
strcpy(name, obj.name);
grade = obj.grade;
}
}
Run Code Online (Sandbox Code Playgroud)
因此它具有非常简单的数据结构及其特殊功能.我是新的重载运算符,所以它可能没有正确实现.现在,我尝试做的是创建这些对象的简单数组.考虑我的主要功能:
Subject *collection = new Subject[3];
char tmp[100];
int grade;
for(int i = 0 ; i < 3; i ++){
cin …Run Code Online (Sandbox Code Playgroud) 说你有班级学生:
class Student{
char *_name;
Student(char *name){
_name = new char[strlen(name)+1];
strcpy(_name, name);
}
void setName(char *name){
_name = new char[strlen(name)+1];
strcpy(_name, name);
}
char* getName(){return _name;}
}
Run Code Online (Sandbox Code Playgroud)
现在,它只是一个基础课程.当我这样做:
Student s("Mike");
Student s1 = s; // calls default copy constructor
s1.setName("Bruce");
cout << s.getName();
cout << s1.getName();
Run Code Online (Sandbox Code Playgroud)
他们现在不应该被称为Bruce,因为复制构造函数将地址复制到源char并且两个指针指向同一个东西吗?