升升哥
2017-09-29 01:15
package com.ls.action;
import com.ls.entity.User;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
public class LoginAction extends ActionSupport implements ModelDriven<User>{
private static final long serialVersionUID = 2420947456421303802L;
private User user =new User();
public String login() {
if(user.getUsername()==null || " ".equals(user.getUsername())){
this.addFieldError("username", "姓名不能为空");
return INPUT;
}
System.out.println(user.getUsername());
System.out.println(user.getBookList().get(0).getUsername());
System.out.println(user.getBookList().get(1).getUsername());
return SUCCESS;
}
@Override
public User getModel() {
// TODO Auto-generated method stub
return user;
}
}
莫名哦
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="default" namespace="/" extends="struts-default">
<action name="LoginAction" class="com.ls.action.LoginAction" method="login">
<result >/success.jsp</result>
<result name="input">/index.jsp</result>
</action>
</package>
</struts>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<%
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>My JSP 'index.jsp' starting page</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="LoginAction.action" method="post" >
<input type="text" name="username"/><s:fielderror name="username"></s:fielderror><br/>
<input type="text" name="password"/><br/>
<input type="text" name="bookList[0].username"/><br/>
<input type="text" name="bookList[1].username"/><br/>
<input type="text" name="age"/><br>
<input type="submit" value="提交"/><br/>
</form>
</body>
</html>
Struts2入门
95061 学习 · 456 问题
相似问题