<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"><struts> <package name="struts" extends="struts-default"> <action name="login" class="action.LoginAction"> <result name="SUCCESS">/index.jsp</result> <result name="ERROR">/login.jsp</result> </action> </package></struts>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <head> <base href="<%=basePath%>"> <title>登录</title> <meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">--> </head> <body><form action="login.action" method = "post"> 用户名:<input type = "text" name = "username"><br> 密码:<input type = "password" name ="password"><br> <input type = "submit" value = "登录"><br> </form> </body></html>
package action;import vo.User;import dao.impl.*;import com.opensymphony.xwork2.ActionSupport;public class LoginAction extends ActionSupport{ private User user; String uer = user.getName(); String pas = user.getPassword(); public String execute() throws Exception{ System.out.println("action"); boolean validated = false; userDao ud = new userDao(); ud.validateUser(uer, pas); if(ud!=null){ validated=true; } if(validated){ return SUCCESS; }else{ return ERROR; } }}
相关分类