简单Blog项目笔记之四:用户注册、分配用户名对应的域名
2012-12-12 14:45
489 查看
一:填写注册内容
这块儿除了原来写的,还有头像的选择<s:form action="userInfo_addUserInfo"> <tr > <td width="73" height="30" bgcolor="F9F9F9">用户名</td> <td width="288" height="30" align="left" bgcolor="#FFFFFF"><s:textfield name="account"/><s:fielderror><s:param value="%{'account'}"/></s:fielderror></td> <td width="82" height="30">真实姓名</td> <td width="303" height="30" align="left" bgcolor="#FFFFFF"><s:textfield name ="realname"/><s:fielderror><s:param value="%{'realname'}"/></s:fielderror></td>
这些没什么可说的,
每个后边跟自己的错误定义 比都放在一起好:<s:fielderror> <s:param value=> </s:fielderror>
这是头像的选择:
做成单选按钮,一起传参给action
<td height="72"><img src="images/headgif/1.gif" width="60" height="60"> <br><br> <input name="headgif" type="radio" value="images/headgif/1.gif" checked class="button"></td> <td><img src="images/headgif/2.gif" width="60" height="60"> <br> <br> <input type="radio" name="headgif" value="images/headgif/2.gif" class="button"></td>
注册也有上一次分析的校验码:
不同的验证码主要还是image.jsp
<tr> <td height="30" bgcolor="F9F9F9">校验码</td> <td height="30" colspan="3" align="left" bgcolor="#FFFFFF"><s:textfield name ="code"/><s:fielderror><s:param value="%{'code'}"/></s:fielderror></td> </tr> <tr > <td height="30" bgcolor="#FFFFFF"> </td> <td height="30" colspan="3" align="left" bgcolor="#FFFFFF"><a href="javascript:refreshImg('validateCodeImg');"><img src="image.jsp" name="validateCodeImg" border=0 id="validateCodeImg" /></a></td> </tr>
二:action,创建用户名对应的域名
还是先validatepublic void validateAddUserInfo() {
hql = "from UserInfo where account= '" + userInfo.getAccount()+ "'"; if (null != objectDao.queryFrom(hql)) { this.addFieldError("account", "用户名重复,请重新输入!"); }检查用户名是否唯一
检查完之后,把md5信息加密后的密码覆盖进去
userInfo.setPassword(com.mr.tools.ValidateExpression.encodeMD5(userInfo .getPassword())); userInfo.setHomepage(userInfo.getHomepage() + userInfo.getAccount()); boolean flag = objectDao.saveT(userInfo);
如果以上都成功,那就准备给用户分配地址
if (flag) { String descPath = ServletActionContext.getRequest().getRealPath("/" + userInfo.getAccount() + ""); String sourPath = ServletActionContext.getRequest().getRealPath("/templet/index.jsp"); if (com.mr.tools.FileOperation.buildJSP(sourPath, descPath,userInfo.getAccount())) { result = "您注册成功!"; request.getSession().setAttribute("freeze",userInfo.getFreeze()); request.getSession().setAttribute("account",userInfo.getAccount()); } }
这块儿比较绕:
把用户名取出来,然后用getRealPath()用于返回绝对路径,即使这是 /用户名不存在,也能返回地址
然后是取出早就预存好的模版的地址,交给bulidJsp处理
public static boolean buildJSP(String souPath, String desPath, String title) { FileInputStream fileinputstream = null; byte[] bytes = null; try { fileinputstream = new FileInputStream(souPath); bytes = new byte[1024 * 5]; //5k缓存 fileinputstream.read(bytes); fileinputstream.close(); String templateContent = new String(bytes); File file = new File(desPath); if(!file.exists()){ //没有则创建 file.mkdir(); } desPath=desPath+"/index.jsp"; //用户名 + '/index.jsp FileOutputStream fileoutputstream = new FileOutputStream(desPath); byte tag_bytes[] = templateContent.getBytes(); fileoutputstream.write(tag_bytes); //创建路径 fileoutputstream.close(); return true; } catch (Exception e) { System.out.println(e); return false; } }
绕了一大圈,总算把用户名对应的的文件夹和jsp文件创建好了
三:用户名/index.jsp中的内容
<% String path1=request.getServletPath(); path1 = path1.substring(1); path1=path1.substring(0, path1.indexOf("/")); response.sendRedirect("userInfo_goinUser.htm?account="+path1+""); %>
Substring(1)是用来去掉传过来字串里的头一个标记“/”
然后截取到下一个“/”,
最后重定向过去
相关文章推荐
- Django商城项目笔记No.7用户部分-注册接口-判断用户名和手机号是否存在
- 简单Blog项目笔记之三:用户登录模块(验证码、MD5)
- nodejs基础教程-简单blog(8)--展示用户注册信息列表
- 简单Blog项目笔记之一:Hibernate管理Dao层
- 简单Blog项目笔记之十:上传照片,显示照片
- Django商城项目笔记No.6用户部分-注册接口-短信验证码实现celery异步
- 简单Blog项目笔记之二:首页显示推荐信息
- ngrok 服务可以分配给你一个域名让你本地的web项目提供给外网访问__个人微信开发笔记
- 网络编程学习笔记二(实现一个基于简单TCP的用户注册程序)
- 简单Blog项目笔记之九:实现 全选/反选
- Django商城项目笔记No.9用户部分-注册接口签发JWTtoken
- java在线聊天项目 客户端登陆窗口LoginDialog的注册用户功能 修改注册逻辑 增空用户名密码的反馈 增加showMessageDialog()提示框
- 简单Blog项目笔记之七:文章的评论
- 简单Blog项目笔记之八:文章的显示
- 简单Blog项目笔记之六:文章增删
- Django商城项目笔记No.8用户部分-注册接口实现
- 简单Blog项目笔记之五:文章标签
- 简单CMS项目笔记之四:信息显示(列表显示和显示具体单项)
- 新手教你学Spring MVC4.0+MyBatis+MySQL5.0实现简单用户注册登录程序(一)
- 毕设(排课系统)笔记1---用户注册(一)