复制代码
6.实现Action:
在src中新建包action,创建类LoginAction类:(附代码LoginAction.java)
复制代码
package com.red.action;
import com.opensymphony.xwork2.ActionSupport;
import com.red.dao.IUserDAO;
import com.red.dao.impl.UserDAO;
import com.red.vo.User;
/**
* 用户登录action
* @author Red
*
*/
public class LoginAction extends ActionSupport{
private String username;
private String password;
//处理用户请求的execute方法
public String execute() throws Exception{
boolean validated=false;//验证成功标识
IUserDAO userDAO=new UserDAO();
User user=userDAO.validateUser(getUsername(),getPassword());
if(user!=null)
{
validated=true;
}
if(validated)
{
//验证成功返回字符串“success”
return SUCCESS;
}
else
{
//验证失败返回字符串“error”
return ERROR;
}
}
public String getUsername(){
return username;
}
public void setUsername(String username){
this.username=username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
复制代码
7.在struts.xml 中配置action:(附代码:struts.xml)
复制代码
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
复制代码
四.V层开发:
就是写当个JSP文件。源码序列分别是:index.jsp;welcome.jsp;error.jsp
复制代码
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<
html>
用户名:
密码: