【struts2】简单登陆页为空判断

1.    在struts使用属性注入POJO模式进行登陆页判断的时候,判断条件是否为空必须使用.equals("")来判断,不能使用 == ""的方式来判断

工程目录:
登陆相关代码:

package com.test.action;

import java.io.File;
import java.util.List;
import java.util.Map;

import com.opensymphony.xwork2.ActionSupport;
import com.test.bean.LoginBean;
import com.test.bean.UserBean;

public class formAction extends ActionSupport {

	private static final long serialVersionUID = -2757669937510150666L;
	
	private LoginBean loginBean;
	
	private String shuzi;
	
	private String zijie;
	
	private List<UserBean> list;
	
	private Map<String, UserBean> map;
	
	public LoginBean getLoginBean() {
		return loginBean;
	}

	public void setLoginBean(LoginBean loginBean) {
		this.loginBean = loginBean;
	}

	public Map<String, UserBean> getMap() {
		return map;
	}

	public void setMap(Map<String, UserBean> map) {
		this.map = map;
	}

	public List<UserBean> getList() {
		return list;
	}

	public void setList(List<UserBean> list) {
		this.list = list;
	}

	public String getShuzi() {
		return shuzi;
	}

	public void setShuzi(String shuzi) {
		this.shuzi = shuzi;
	}

	public String getZijie() {
		return zijie;
	}

	public void setZijie(String zijie) {
		this.zijie = zijie;
	}

	private File file;

	public File getFile() {
		return file;
	}

	public void setFile(File file) {
		this.file = file;
	}

	private String fileContentType;
	
	private String fileFileName;
	
	public String getFileContentType() {
		return fileContentType;
	}

	public void setFileContentType(String fileContentType) {
		this.fileContentType = fileContentType;
	}

	public String getFileFileName() {
		return fileFileName;
	}

	public void setFileFileName(String fileFileName) {
		this.fileFileName = fileFileName;
	}

	private String[] number;

	public String[] getNumber() {
		return number;
	}

	public void setNumber(String[] number) {
		this.number = number;
	}
	
	public void testNumber(){
		//System.out.println(number.toString()+"shuzi"+shuzi.toString()+"zijie"+zijie.toString());
		for(int i=0;i<number.length;i++){
			System.out.println(number[i]);
		}
		
	}
	
	public void testFile(){
		System.out.println(this.getFileFileName());
		System.out.println(file.getName());
	}
	
	public String excute(){
		System.out.println("执行excute");
		return "success";
		
	}
	
	public String list(){
		for(UserBean userBean : list){
			System.out.println("name=: "+userBean.getName()+"age=: "+userBean.getAge());
		}
		return null;
	}
	
	public String map(){
		for(String key : map.keySet()){
			UserBean ub = map.get(key);
			System.out.println(key+"  "+ub.getName()+"  "+ub.getAge());
		}
		return null;
		
	}
	
	public String login(){
		if(loginBean.getName()== null || loginBean.getName().equals("")){
			return "loginError";
		}else{
			return "login";
		}
		
		
		
	}

}

login.jsp:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<form method="post" action="${pageContext.request.contextPath}/formAction/test_login.action" id="updateText" > 
	<table>
		<tr>
			<td height="28px" width="80">登陆名</td>
			<td height="28px" width="80"><input type="text" style="width:240px;" name="loginBean.name" id="username_login" /></td>
		</tr>
		<tr>
			<td height="28px" width="80">密码</td>
			<td height="28px" width="80"><input type="text" style="width:240px;" name="loginBean.password" id="userpw_login" /></td>
		</tr>
		<tr>
			<td>
				<input id="submitBtn1" type="submit" value="确定" style="padding:3px 25px;"/>
			</td>
		</tr>
	</table>
</form> 
</body>
</html>

struts.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
	"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
	"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
	
		<package name="company" extends="struts-default" >
			<!-- 动态方法调用方式2:通配符方式
				 使用{1} 取出第一个星号通配的内容
			  -->
			<action name="test_*" class="com.test.action.formAction" method="{1}" >
			
			<result name="success">/WEB-INF/view/success.jsp</result>
			<result name="login">/Hellow.jsp</result>
			<result name="loginError">/WEB-INF/view/login.jsp</result>
			</action>
		</package>
</struts>

猜你喜欢

转载自blog.csdn.net/liangayang/article/details/80664263
今日推荐