zoukankan      html  css  js  c++  java
  • struts配置及检验

    登录页面
    <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="s" uri="/struts-tags"%> <!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> <center> <s:fielderror/> <form action="hello" method="post"> 账号:<input type="text" name="username"/><br /> 密码:<input type="password" name="password"/><br /> <input type="submit" value="登录"/> </form> </center> </body> </html>


    struts配置及web配置
    <?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="default" namespace="/" extends="struts-default">
            <action name="hello" class="com.action.HelloAction">
                <result name="success">/success.jsp</result>
                <result name="input">/index.jsp</result>
                
            </action>
        </package>
    </struts>
    
    
    
    
    
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:web="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" id="WebApp_9" version="2.4">
      <display-name>Struts Blank</display-name>
      <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
      </filter>
      <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
      </filter-mapping>
      <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
      </welcome-file-list>
    </web-app>


    参数检验类HelloActio
    package com.action;
    
    import org.apache.commons.lang.StringUtils;
    
    import com.opensymphony.xwork2.ActionSupport;
    
    public class HelloAction extends ActionSupport{
    	
    private static final long serialVersionUID=1L;
    private String username;
    private String pasdword;
    public String getUsername() {
    	return username;
    }
    
    
    public void setUsername(String username) {
    	this.username = username;
    }
    
    
    public String getPasdword() {
    	return pasdword;
    }
    
    
    public void setPasdword(String pasdword) {
    	this.pasdword = pasdword;
    }
    
     public void validateUsername()
     {
    	 
    	 if(StringUtils.isBlank(username)) {
    		 addFieldError(username, "名字不能空");
    	 }
     }
    
    
    @Override
    	public String execute() throws Exception {
    		
    		return "success";
    	}
    }
    
    
    
    
    校验结束,数据正确页面;
    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
       <%@ taglib prefix="s" uri="/struts-tags"%>
    <!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>
    
       执行
     
    </body>
    </html>
    
    
    
    
     



  • 相关阅读:
    Mac10.12下Python3.4调用oracle
    java或Jmeter实现两个日期相加减(2003-06-01-2003-05-01)
    Jmeter使用JDBC请求简介
    草火论
    学习五有
    中国特色的信息技术实践中的两种思路:信息索引化和信息持久化
    软件工程基本原理
    东亚文化原理
    临死之前我要写一本《中国哲学史——以自然主义和人道主义的矛盾为视角》
    总体软件观五个规律
  • 原文地址:https://www.cnblogs.com/zhangjiaqi123/p/9107066.html
Copyright © 2011-2022 走看看