如何使用 struts 表单字段 (s:textfield, s:password) 并使用 materializecss 框架设置样式?
how to use struts form fields (s:textfield, s:password) and style them using materializecss framework?
<form class = "col l12 s12">
<div class = "row">
<div class="input-field col l6 s6">
<input id="firstName" type="text" class="validate">
<label for="firstName">First Name</label>
</div>
</div>
</form>
我想在上面的代码上应用Struts2来获取firstName
的值。我应该怎么做?
编辑(注册表的整个 jsp 代码):
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<!--Import Google Icon Font-->
<link href="http://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<!--Import materialize.css-->
<link type="text/css" rel="stylesheet" href="css/materialize.min.css" media="screen,projection"/>
<link type="text/css" rel="stylesheet" href="css/register.css">
<!--Let browser know website is optimized for mobile-->
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</head>
<body>
<!--Import jQuery before materialize.js-->
<script type="text/javascript" src="js/jquery-2.1.4.min.js"></script>
<script type="text/javascript" src="js/materialize.min.js"></script>
<div class = "background">
<h1 class = "center-align white-text">Register</h1>
</div>
<div class = "container formContainer white z-depth-2">
<div class = "row formParent">
<form class = "col l12 s12">
<div class = "row">
<div class="input-field col l6 s6">
<input id="firstName" type="text" class="validate">
<label for="firstName">First Name</label>
</div>
<div class="input-field col l6 s6">
<input id="lastName" type="text" class="validate">
<label for="lastName">Last Name</label>
</div>
</div>
<div class = "row">
<div class="input-field col l12 s12">
<input id="username" type="text" class="validate">
<label for="username">Username</label>
</div>
</div>
<div class = "row">
<div class="input-field col s6">
<input id="password" type="password" class="validate">
<label for="password">Enter password</label>
</div>
<div class="input-field col s6">
<input id="repeatPassword" type="password" class="validate">
<label for="repeatPassword">Repeat password</label>
</div>
</div>
<div class="row">
<div class="input-field col s12">
<input id="email" type="email" class="validate">
<label for="email" data-error="wrong" data-success="right">Email</label>
</div>
</div>
<div class = "row formButtons">
<button class="btn waves-effect waves-light right submitButton purple accent-4" type="submit" name="submit">Submit</button>
<a href = 'index.jsp' class = 'btn waves-effect waves-dark right cancelButton purple accent-1'>Cancel</a>
</div>
</form>
</div>
</div>
</body>
在上面的 jsp 代码中,我希望获取字段值并且我希望能够将它们分配给以下 actionClass:
public class registerAction {
private String firstName, lastName, username;
public String execute(){
return "";
}
}
但我不知道如何将 struts 前缀应用于使用物化 css 输入字段的 jsp 表单。
这是 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>
<constant name="struts.devMode" value="true"/>
<package name="helloWorld" extends="struts-default">
<action name="hello" class = "com.bugManager.registerAction" method="execute">
<result name="success">helloWorld.jsp</result>
</action>
</package>
</struts>
好的,我自己做的。如果有人想在 struts2 中使用 materializecss 表单标签,请执行以下操作:
1.将此行添加到 struts.xml
<constant name="struts.ui.theme" value="simple" />
我的更新和工作 struts.xml
<struts>
<constant name="struts.devMode" value="true"/>
<constant name="struts.ui.theme" value="simple" /> <!-- this is the line which helps in applying materializecss's styling to the form elements -->
<package name="com.bugManager" extends="struts-default">
<action name="register" class = "com.bugManager.registerAction" method="execute">
<result name="success">helloWorld.jsp</result>
</action>
</package>
</struts>
my helloWorld.jsp:(任何重定向页面,我创建此页面是为了测试值是否被正确映射和存储)
<html>
<head>
<title>Hello World Strut</title>
</head>
<body>
Hello from <s:property value = "firstName"/> <s:property value = "lastName"/> <s:property value = "username"/> <s:property value = "password"/>
<s:property value="email"/>
</body>
</html>
2。然后改
表单标签
<form></form> to <s:form></s:form>
任何文本或电子邮件输入标签到
<s:textfield />
密码字段到
<s:password />
提交可以保持不变
查看下面给出的示例表单代码
<s:form class = "col l12 s12" action = "register">
<div class = "row">
<div class="input-field col l6 s6">
<s:textfield name = "firstName" id="firstName" type="text" class="validate"/>
<label for="firstName">First Name</label>
</div>
<div class="input-field col l6 s6">
<s:textfield name = "lastName" id="lastName" type="text" class="validate"/>
<label for="lastName">Last Name</label>
</div>
</div>
<div class = "row">
<div class="input-field col l12 s12">
<s:textfield name = "username" id="username" type="text" class="validate"/>
<label for="username">Username</label>
</div>
</div>
<div class = "row">
<div class="input-field col s6">
<s:password name = "password" id="password" type="password" class="validate"/>
<label for="password">Enter password</label>
</div>
<div class = 'input-field col s6'>
<s:password name = "password" id="repeatPassword" type="password" class="validate"/>
<label for="repeatPassword">Repeat password</label>
</div>
</div>
<div class="row">
<div class="input-field col s12">
<s:textfield name = "email" id="email" type="email"/>
<label for="email">Email</label>
</div>
</div>
<div class = "row formButtons">
<button class="btn waves-effect waves-light right submitButton purple accent-4" type="submit" name="submit">Submit</button>
<a href = 'index.jsp' class = 'btn waves-effect waves-dark right cancelButton purple accent-1'>Cancel</a>
</div>
</s:form>
在此处查看所有 struts 表单标签: http://www.tutorialspoint.com/struts_2/struts_form_tags.htm
我希望这对所有试图在 Struts2 中实施 materializecss 的人有所帮助!
<form class = "col l12 s12">
<div class = "row">
<div class="input-field col l6 s6">
<input id="firstName" type="text" class="validate">
<label for="firstName">First Name</label>
</div>
</div>
</form>
我想在上面的代码上应用Struts2来获取firstName
的值。我应该怎么做?
编辑(注册表的整个 jsp 代码):
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<!--Import Google Icon Font-->
<link href="http://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<!--Import materialize.css-->
<link type="text/css" rel="stylesheet" href="css/materialize.min.css" media="screen,projection"/>
<link type="text/css" rel="stylesheet" href="css/register.css">
<!--Let browser know website is optimized for mobile-->
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</head>
<body>
<!--Import jQuery before materialize.js-->
<script type="text/javascript" src="js/jquery-2.1.4.min.js"></script>
<script type="text/javascript" src="js/materialize.min.js"></script>
<div class = "background">
<h1 class = "center-align white-text">Register</h1>
</div>
<div class = "container formContainer white z-depth-2">
<div class = "row formParent">
<form class = "col l12 s12">
<div class = "row">
<div class="input-field col l6 s6">
<input id="firstName" type="text" class="validate">
<label for="firstName">First Name</label>
</div>
<div class="input-field col l6 s6">
<input id="lastName" type="text" class="validate">
<label for="lastName">Last Name</label>
</div>
</div>
<div class = "row">
<div class="input-field col l12 s12">
<input id="username" type="text" class="validate">
<label for="username">Username</label>
</div>
</div>
<div class = "row">
<div class="input-field col s6">
<input id="password" type="password" class="validate">
<label for="password">Enter password</label>
</div>
<div class="input-field col s6">
<input id="repeatPassword" type="password" class="validate">
<label for="repeatPassword">Repeat password</label>
</div>
</div>
<div class="row">
<div class="input-field col s12">
<input id="email" type="email" class="validate">
<label for="email" data-error="wrong" data-success="right">Email</label>
</div>
</div>
<div class = "row formButtons">
<button class="btn waves-effect waves-light right submitButton purple accent-4" type="submit" name="submit">Submit</button>
<a href = 'index.jsp' class = 'btn waves-effect waves-dark right cancelButton purple accent-1'>Cancel</a>
</div>
</form>
</div>
</div>
</body>
在上面的 jsp 代码中,我希望获取字段值并且我希望能够将它们分配给以下 actionClass:
public class registerAction {
private String firstName, lastName, username;
public String execute(){
return "";
}
}
但我不知道如何将 struts 前缀应用于使用物化 css 输入字段的 jsp 表单。
这是 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>
<constant name="struts.devMode" value="true"/>
<package name="helloWorld" extends="struts-default">
<action name="hello" class = "com.bugManager.registerAction" method="execute">
<result name="success">helloWorld.jsp</result>
</action>
</package>
</struts>
好的,我自己做的。如果有人想在 struts2 中使用 materializecss 表单标签,请执行以下操作:
1.将此行添加到 struts.xml
<constant name="struts.ui.theme" value="simple" />
我的更新和工作 struts.xml
<struts>
<constant name="struts.devMode" value="true"/>
<constant name="struts.ui.theme" value="simple" /> <!-- this is the line which helps in applying materializecss's styling to the form elements -->
<package name="com.bugManager" extends="struts-default">
<action name="register" class = "com.bugManager.registerAction" method="execute">
<result name="success">helloWorld.jsp</result>
</action>
</package>
</struts>
my helloWorld.jsp:(任何重定向页面,我创建此页面是为了测试值是否被正确映射和存储)
<html>
<head>
<title>Hello World Strut</title>
</head>
<body>
Hello from <s:property value = "firstName"/> <s:property value = "lastName"/> <s:property value = "username"/> <s:property value = "password"/>
<s:property value="email"/>
</body>
</html>
2。然后改
表单标签
<form></form> to <s:form></s:form>
任何文本或电子邮件输入标签到
<s:textfield />
密码字段到
<s:password />
提交可以保持不变
查看下面给出的示例表单代码
<s:form class = "col l12 s12" action = "register">
<div class = "row">
<div class="input-field col l6 s6">
<s:textfield name = "firstName" id="firstName" type="text" class="validate"/>
<label for="firstName">First Name</label>
</div>
<div class="input-field col l6 s6">
<s:textfield name = "lastName" id="lastName" type="text" class="validate"/>
<label for="lastName">Last Name</label>
</div>
</div>
<div class = "row">
<div class="input-field col l12 s12">
<s:textfield name = "username" id="username" type="text" class="validate"/>
<label for="username">Username</label>
</div>
</div>
<div class = "row">
<div class="input-field col s6">
<s:password name = "password" id="password" type="password" class="validate"/>
<label for="password">Enter password</label>
</div>
<div class = 'input-field col s6'>
<s:password name = "password" id="repeatPassword" type="password" class="validate"/>
<label for="repeatPassword">Repeat password</label>
</div>
</div>
<div class="row">
<div class="input-field col s12">
<s:textfield name = "email" id="email" type="email"/>
<label for="email">Email</label>
</div>
</div>
<div class = "row formButtons">
<button class="btn waves-effect waves-light right submitButton purple accent-4" type="submit" name="submit">Submit</button>
<a href = 'index.jsp' class = 'btn waves-effect waves-dark right cancelButton purple accent-1'>Cancel</a>
</div>
</s:form>
在此处查看所有 struts 表单标签: http://www.tutorialspoint.com/struts_2/struts_form_tags.htm
我希望这对所有试图在 Struts2 中实施 materializecss 的人有所帮助!