好想没有这个标签啊

来源:4-10 关于input的代码演示-深入Struts2

升升哥

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;

}




}


写回答 关注

3回答

  • 升升哥
    2017-09-29 01:17:55

    http://img3.mukewang.com/59cd2eae0001c0c819200944.jpg莫名哦

  • 升升哥
    2017-09-29 01:16:56

    <?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>    


  • 升升哥
    2017-09-29 01:16:31

    <%@ 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入门

本教程带你踏上Struts2学习之旅,对Struts2进行更深入讲解

95062 学习 · 456 问题

查看课程

相似问题