eclipse学习(第二章:初识ssh)——20.struts的标签(③表单标签)
前言
本文参考自以下网站做的实践日志记录。
https://www.w3cschool.cn/struts_2/struts_form_tags.html
本文主要针对的是一些简单的表单ui标签,一些多选单选标签,下拉框选择标签。
一开始的初始化项目和修改web.xml是必须的,然后看你要使用哪个标签就跳转过去加入对应的内容即可启动及测试成功了。
初始化项目及jar包拉取
修改web.xml
注意我这里针对性的设置了i18n的数据源名称,如果你要改变名称请自行更改。
<?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/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>ssh_learn_form_label</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
<init-param>
<param-name>struts.devMode</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>struts.custom.i18n.resources</param-name>
<param-value>email</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
1、一些简单的ui界面标签
创建FormAction
package com.label.form.action;
import java.io.File;
import java.io.Serializable;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.InterceptorRef;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import com.opensymphony.xwork2.ActionSupport;
@Namespace("/select")
public class FormAction extends ActionSupport implements Serializable{
public File getFile() {
return file;
}
public void setFile(File file) {
this.file = file;
}
public String getFileFileName() {
return fileFileName;
}
public void setFileFileName(String fileFileName) {
this.fileFileName = fileFileName;
}
public String getFileContentType() {
return fileContentType;
}
public void setFileContentType(String fileContentType) {
this.fileContentType = fileContentType;
}
public String getHidden() {
return hidden;
}
public void setHidden(String hidden) {
this.hidden = hidden;
}
public String getTopic() {
return topic;
}
public void setTopic(String topic) {
this.topic = topic;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getArea() {
return area;
}
public void setArea(String area) {
this.area = area;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
private String name;
pr