日期:2014-05-20 浏览次数:20704 次
package cc.openhome;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/hello.view")
public class HellowServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
String username = request.getParameter("username");
String passwd = request.getParameter("password");
if(checkLogin(username, passwd)){
System.out.println("welcome");
}
else{
System.out.println("sorry");
}
}
private boolean checkLogin(String username, String passwd) throws IOException {
// TODO Auto-generated method stub
String user1 = "zhangsan";
String user2 = "lisi";
String psd1 = "123";
String psd2 = "234";
if(username==user1 && passwd==psd1){
return true;
}
else if(username==user2 && passwd==psd2){
return true;
}
else{
return false;
}
}
}
if(username==user1 && passwd==psd1){
return true;
}
else if(username==user2 && passwd==psd2){
return true;
}
else{
return false;
}
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
String test="test";
if(test=="test"){
System.out.println("相等");
}
}
}