*Struts之html标签的学习

news/2024/6/17 14:16:22 标签: html, struts, file, string, exception, action
htmledit_views">


1。锚点链接
<html:link linkName="top">顶部</html:link>
在一篇文章的结尾处编写如下 代码。
<html:link href="" anchor="top">回到顶部</html:link>
href属性值为"",指定了链接的目标页面为当前页面
  全局链接
<global-forwards >
    <forward name="globalerror" path="/Errors.jsp" />
</global-forwards>
<html:link forward="globalerror">显示错误信息!</html:link>
 传参
<%
  String usersex="Man";
  Session.setAttribute("mysex",usersex);
%>
将该变量作为参数通过链接进行传递。
<html:link page="/welcome.jsp" paramId="sex" paramName="mysex">显示性别!</html:link>
__________________________
将userinfo中的username属性值作为参数通过链接进行传递。
假设userinfo中存在username和userpwd两个属性,并且username="yxq",userpwd="123",

session.setAttribute ("userBean",userinfo)。
<html:link page="/welcome.jsp" paramId="name" paramName="userinfo"

paramProperty="username"/>显示用户名!</html:link>
上述代码生成如下HTML元素。
<a href="/Logon/welcome.jsp?name=yxq">显示用户名!</html:link>
________________________________
<% Hashtable logonuser=new Hashtable();
  logonuser.put("username","yxq");
  logonusr.put("userpwd","123");
  session.setAttribute("userinfo",logonuser);
%>
<html:link page="/logon.do" name="userinfo" scope="session"/>登录</html:link>
上述代码生成如下HTML元素。<a href="/office/logon.do?username=yxq&amp;userpwd=123">
2.<html:form action="logon" method="post" focus="password">
没有name属性,因为在这里设置了,可直接用logonform
<action      path="/logon"  name="logonform"type="logon.action.LogonAction"/>
3<html:textarea>多行多列文本输入标签
4.文件上传
<html:file>
csdn空间4/struts之上传的学习.rar

5。errror
 errors.add("nameerror",new ActionMessage("reg.name.error"));
    errors.add("pwderror",new ActionMessage("reg.pwd.error"));
tr><td align="right">用户名:</td>
 <td><html:text property="username"/></td></tr>
  <tr><td colspan="2"><html:errors property="nameerror"/></td></tr>   //显示用户名的相关

信息  <tr><td align="right">密&nbsp;&nbsp;码:</td>
     <td><html:password property="userpwd" redisplay="false"/></td></tr>
    <tr><td colspan="2"><html:errors property="pwderror"/></td></tr>   //显示用户密码的相

关信息

 

 

 

 

 

 

______________________

Struts文件上传
<html:form action="upfile" method="post" focus="file" enctype="multipart/form-data" >
选择文件:<html:file property="file" size="30"/
-----------------------------
import org.apache.struts.upload.FormFile;
UpFileForm fileform = (UpFileForm) form;
FormFile upfile = fileform.getFile();
 String filename = upfile.getFileName();
  int filesize = upfile.getFileSize();
 String filepath = request.getRealPath("") + "/upfile";//上传目录
File file = new File(filepath, filename);
  byte a[] = new byte[filesize];
try {
   InputStream in = upfile.getInputStream();
   int read = 0;
   int allread = 0;
   while (allread < filesize) {
    read = in.read(a, allread, filesize);
    allread += read;
   }
   FileOutputStream out = new FileOutputStream(file);
   out.write(a);
   in.close();
   out.close();
   messages.add("success", new ActionMessage("file.up.file.success"));
   saveMessages(request, messages);
  } catch (Exception e) {
   e.printStackTrace();
  }


http://www.niftyadmin.cn/n/1425552.html

相关文章

ABC类IP地址划分_wuli大世界_新浪博客

IANA&#xff08;Internet Assigned Numbers Authority&#xff09;互联网地址编码分配机构为了保障IP地址的唯一性&#xff0c;便于地址的分配及管理&#xff0c;将IP地址划分为了ABCDE五类。每个类别的网络部分和主机部分都有相应的规则&#xff0c;DE类不划分网络部分和主机…

Struts集成Spring出错:Servlet action is not available 的解决

其实分文件夹放就不会出这个错的。spring的jar放入spring文件夹中&#xff0c;hibernate的jar放入hibernate文件夹中 Q:确认了配置文件都没有错了&#xff0c;但是还是Servlet action is not available &#xff0c;action里面只是打印一句话而已。然后我就分开做 整和SSH看…

ubuntu12.04安装QQ以及搜狗输入法问题解决

安装最新QQ&#xff1a;1安装winehq:sudo add-apt-repository ppa:wine/wine-buildssudo apt-get updatesudo apt-get install winehq-devel2下载QQ&#xff1a;百度云链接&#xff1a;https://pan.baidu.com/s/1dE2sZNr 密码: evgftar xvf wineQQ8.9_19990.tar.xz -C ~/3OK安…

ABC类IP地址划分

IANA&#xff08;Internet Assigned Numbers Authority&#xff09;互联网地址编码分配机构为了保障IP地址的唯一性&#xff0c;便于地址的分配及管理&#xff0c;将IP地址划分为了ABCDE五类。每个类别的网络部分和主机部分都有相应的规则&#xff0c;DE类不划分网络部分和主机…

* ssh+log4j+security+dwr的配置

这些配置常见问题有&#xff1a;。。。。 1.ssh的配置中jar要分别放入自己的文件夹&#xff0c;否则会冲突&#xff0c;后果就是sturs中的servlet action is aviable。的错误。 基本模块 附件&#xff1a;csdn空间4/sshlog4jsecuritydwr

shell常见的语句结构_wuli大世界_新浪博客

一.if语句结构 1.单分支的if语句if 条件测试操作then命令序列fi2.双分支的if语句if 条件测试操作then命令序列1else 命令序列2fi3.多分支的if语句if 条件测试操作1then命令序列1elif 条件测试操作2then 命令序列2else 命令序列3fi二.for循环语句for语句的结构for 变量名…

高性能网站建设之 MS Sql Server数据库分区

什么是数据库分区&#xff1f;数据库分区是一种对表的横向分割&#xff0c;Sql server 2005企业版和之后的Sql server版本才提供这种技术&#xff0c;这种对表的横向分割不同于2000中的表分割&#xff0c;它对访问用户是透明的&#xff0c;用户并不会感觉的表被横向分割了。&am…