?? loginaction.java
字號(hào):
package mypack;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
public class LoginAction extends Action {
protected String checkUser(String username, String password) {
String user = null;
// You would normally do some real User lookup here, but
// for this example we will have only one valid username "swq"
if ( username.equals("swq") && password.equals("1234") ) {
user = new String("Sun weiqin");
}
return user;
}
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
String user = null;
// Default target to success
String target = new String("success");
// Use the LoginForm to get the request parameters
String username = ((LoginForm)form).getUsername();
String password = ((LoginForm)form).getPassword();
user = checkUser(username, password);
// Set the target to failure
if ( user == null ) {
((LoginForm)form).setUsername("username");
((LoginForm)form).setPassword("password");
target = new String("failure");
}
else {
request.setAttribute("USER", user);
}
// Forward to the appropriate View
return (mapping.findForward(target));
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -