<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>创建个性化空间</title>
<META http-equiv=Content-Type content="text/html; charset=utf-8">
<link href="../../css/style1.css" type=text/css rel=stylesheet>
<link href="../../css/style.css" type="text/css" rel="stylesheet">
<script type="text/javascript" src="../../js/common.js"></script>
</head>
<body>
<center>
<table width="50%" border="0" style="margin-top:20px;" align="center" cellpadding="0" cellspacing="0">
<tr>
<td colspan="3">
<table cellpadding="0" cellspacing="0" width="100%" height="62">
<tr>
<td background="../../images/tab01.gif" width="309" valign="top">
<div class="tabhead">创建个性化空间</div>
</td>
<td valign="bottom">
<table cellpadding="0" cellspacing="0" width="100%">
<tr>
<td background="../../images/topcenter.gif" width="100%"></td>
<td><img src="../../images/topright.gif"></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td background="../../images/centerleft.gif"></td>
<td width="100%" bgColor="#e9e9de" >
<table width="100%" border="0" style="margin:5px 0;" cellspacing="0" cellpadding="0" align="center" height="50">
<tr>
<td width="24" align="center" rowspan="3" valign="top" style="padding-top:0px;"><img src="../../images/icon03.gif" width="16" height="16"></td>
<td width="556" style="padding-top:2px;"class="fontgreen">
<b>系统提醒</b>
</td>
</tr>
<tr>
<td style="padding-top:2px;" colspan="2" class="fontgray">
<ol>
<li>
<font color="#ff0000">带*号的选项内容必须填写</font>
</li>
<li>
<font color="#ff0000">注意上传的图片尺寸尽量不要太大</font>
</li>
</ol>
</td>
</tr>
</table>
<form action="createSpace.action" method="post" enctype="multipart/form-data">
<table width="100%" border="0" style="margin:5px 0;" cellspacing="0" cellpadding="0" align="center">
<tr>
<TD width="50%" bgColor=#e9e9de align="right">
<FONT color=#ff9933>*</FONT> 请用一句话形容对跑步的主张:
</TD>
<TD width="50%">
<INPUT class=INPUT1 type=text maxLength=14 name=opinion
style="width:200;height:25" />
</TD>
</tr>
<TR>
<TD width="50%" bgColor=#e9e9de align="right">
<FONT color=#ff9933>*</FONT> 喜欢在什么时段跑步?
</TD>
<TD width="50%">
<input name="runtime" class=radio1 type="radio" value="清晨" />清晨
<input type="radio" name="runtime" class=radio1 value="午后" />午后
<input type="radio" name="runtime" class=radio1 value="黄昏" checked="checked"/>黄昏
</c:otherwise>
</c:choose>
</TD>
</TR>
<TR>
<TD bgColor=#e9e9de width="50%" align="right">
<FONT color=#ff9933>*</FONT> 喜欢独自跑还是结伴跑?
</TD>
<TD width="50%">
<INPUT class=INPUT1 type=text maxLength=20 name=runhabit style="width:200;height:25" />
</TD>
</TR>
<TR>
<TD bgColor=#e9e9de width="50%" align="right">
<FONT color=#ff9933>*</FONT>最喜欢的体育明星:
</TD>
<TD>
<INPUT class=INPUT1 type=text maxLength=20 name=runstar style="width:200;height:25" />
</TD>
</TR>
<TR>
<TD width="50%" bgColor=#e9e9de align="right">
<FONT color=#ff9933>*</FONT> 正在使用的手机:
</TD>
<TD width="50%">
<INPUT class=INPUT1 type=text maxLength=14 name=cellphone
style="width:200;height:25" />
</TD>
</TR>
<TR>
<TD width="50%" bgColor=#e9e9de align="right">
<FONT color=#ff9933>*</FONT> 经常跑步的地点:
</TD>
<TD width="50%">
<INPUT class="INPUT1" type="text" maxLength="14" name="runplace"
style="width:200;height:25" />
</TD>
</TR>
<TR>
<TD bgColor=#e9e9de width="50%" align="right"> 上传个性化形象:</TD>
<TD>
<input type="file" name="icon" style="width:200;height:25" />
</TD>
</TR>
<tr>
<td colSpan="2">
<div align="center">
<input type="submit" value="提交" style="cursor: hand"/>
<input type="reset" value="重置" style="cursor: hand"/>
</div>
</td>
</tr>
</table>
</form>
</td>
<td background="../../images/centeright.gif"></td>
</tr>
<tr>
<td><img src="../../images/bottomleft.gif"></td>
<td background="../../images/bottomcenter.gif"></td>
<td><img src="../../images/bottomright.gif"></td>
</tr>
</table>
</center>
</body>
</html>
package com.briup.run.web.action;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Date;
import java.util.List;
import java.util.Map;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts2.ServletActionContext;
import com.briup.run.common.exception.MemberServiceException;
import com.briup.run.common.ip.IPSeeker;
import com.briup.run.common.transaction.HibernateTransaction;
import com.briup.run.common.util.BeanFactory;
import com.briup.run.common.util.MD5;
import com.briup.run.dao.IMemberDao;
import com.briup.run.pojos.Memberinfo;
import com.briup.run.pojos.MemberinfoWrapper;
import com.briup.run.pojos.Memberspace;
import com.briup.run.service.IMemberService;
import com.briup.run.service.IMessengerService;
import com.briup.run.service.MemberServiceImpl;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class MemberAction extends ActionSupport {
private Memberinfo info;
private String authCode;
private String provinceCity;
private String userName;
private String passwd;
private String email;
private Boolean autoLogin;
private File icon;
private String iconFileName;
private IMessengerService messengerService = (IMessengerService) BeanFactory
.getBean(BeanFactory.MESSENGESERVICE);
private IMemberService memberService = (IMemberService) BeanFactory
.getBean(BeanFactory.MEMBERSERVICE);
public Memberinfo getInfo() {
return info;
}
public void setInfo(Memberinfo info) {
this.info = info;
}
// 登录方法
public String login() throws Exception {
if(autoLogin!=null&&autoLogin){
Cookie cookie1=new Cookie("nickname" ,userName);
Cookie cookie2=new Cookie("password" ,passwd);
cookie1.setMaxAge(999999999);
cookie2.setMaxAge(999999999);
cookie1.setPath("/");
cookie2.setPath("/");
HttpServletResponse response=ServletActionContext.getResponse();
response.addCookie(cookie1);
response.addCookie(cookie2);
}
try {
Map session = ActionContext.getContext().getSession();
session.remove("othermemberspace");
Memberinfo member = memberService.login(userName, passwd);
// 由于重定向,将登录前的状态存储到session中
//session.remove("othermemberspace");
session.put("memberinfo", member);
return "login-true";
} catch (MemberServiceException e) {
e.printStackTrace();
addActionError(e.getMessage());
return "login-false";
}
}
//用户点击注销 跳转到login.jsp页面,把用户登录的信息删除,
public String exit() throws Exception{
Map session = ActionContext.getContext().getSession();
Memberinfo member=(Memberinfo) session.get("memberinfo");
member.setIsonline(0L);
memberService.saveOrUpDate(member);
System.out.println("用户已经注销!");
session.remove("memberinfo");
return "success";
}
// 登录成功后需要在Action中处理的业务
public String afterLogin() throws Exception {
try {
Map session = ActionContext.getContext().getSession();
Memberinfo member = (Memberinfo) ActionContext.getContext()
.getSession().get("memberinfo");
// 获得当前在线人数
int onlineNum = memberService.findMemberinfoOnline();
// 获得短信数量
int newMessage = messengerService.findNewMessageNum(member.getNickname());
// 获得上次登录的时间
Date lastTime = member.getLatestdate();
// 获得ip地址
String ip = ServletActionContext.getRequest().getRemoteAddr();
IPSeeker seeker = IPSeeker.getInstance();
String address1 = seeker.getCountry(ip);
String address2 = seeker.getArea(ip);
String address = address1 + " " + address2;
// 获得积分前十名的用户
List<Memberinfo> list = memberService.findMemberinfoByNum(10);
// 获得系统当前时间
Date nowTime = new Date();
// 封装数据
MemberinfoWrapper mw = new MemberinfoWrapper();
mw.setAddress(address);
mw.setLastDate(lastTime);
mw.setList(list);
mw.setNow(nowTime);
mw.setOnlinenum(onlineNum + "");
mw.setNewMessageNum(newMessage + "");
// 放入session范围
session.put("wrapper", mw);
return "login-true";
} catch (MemberServiceException e) {
e.printStackTrace();
addActionError(e.getMessage());
return "login-false";
}
}
//检查是否自动登录
public String autoLogin(){
HttpServletRequest request = ServletActionContext.getRequest();
Cookie cookie[] = request.getCookies();
if (cookie != null) {
for (int i = 0; i < cookie.length; i++) {
if (cookie[i].getName().equals("nickname")) {
userName = cookie[i].getValue();
}
if (cookie[i].getName().equals("password")) {
passwd = cookie[i].getValue();
}
}
return "success";
}
return "false";
}
// 注册中验证码的验证
public String register() throws Exception {
String auth = (String) ActionContext.getContext().getSession().get(
"authCode");
if (!auth.equals(authCode)) {
addActionError("验证码不正确!");
return "register-false";
}
try {
info.setProvincecity(provinceCity);
memberService.registerMemberinfo(info);
return "register-true";
} catch (MemberServiceException e) {
addActionError(e.getMessage());
return "register-false";
}
}
//*用户修改个人信息
public String saveModify(){
HttpServletRequest request=ServletActionContext.getRequest();
Map session = ActionContext.getContext().getSession();
MD5 md5 = MD5 .getInstance();
//获取当前登录的对象Memberinfo
Memberinfo member = (Memberinfo) ActionContext.getContext().getSession().get("memberinfo");
Memberinfo memberinfo = (Memberinfo) ActionContext.getContext().getSession().get("memberinfo");
session.remove(memberinfo);
String newPassword=md5.getMD5ofStr(request.getParameter("newPasswd"));
String oldPasswd=request.getParameter("oldPasswd");
String newEmail=request.getParameter("email");
String newPasswdQuestion=request.getParameter("passwdQuestion");
String newPasswdAnswer=request.getParameter("passwdAnswer");
String newGender=request.getParameter("gender");
String newProvinceCity=request.getParameter("provinceCity");
String newPhone =request.getParameter("phone");
String newAddress=request.getParameter("address");
int age=Integer.valueOf(request.getParameter("age"));
member.setPassword(newPassword);
member.setEmail(newEmail);
member.setPasswordquestion(newPasswdQuestion);
member.setPasswordanswer(newPasswdAnswer);
member.setGender(newGender);
member.setProvincecity(newProvinceCity);
member.setPhone(newPhone);
member.setAddress(newAddress);
member.setAge(age);
//session.clear();
try {
memberService.saveOrUpDate(member);
session.put("memberinfo", member);
} catch (MemberServiceException e) {
e.printStackTrace();
return "false";
}
return "success";
}
/*
* 用户遗失密码后在找回密码页面上输入用户名,密码提示问题,密码提示答案,
则交给这个Action处理 在调用service层里的findMemberinfoByName(String nickname)
方法从数据库中查找该用户是否存在,如果存在再核实密码提示问题和密码提示答案
是否与数据库中的吻合,是则返回一个新的密码,
*/
public String getBackPasswd(){
HttpServletRequest request=ServletActionContext.getRequest();
Map session = ActionContext.getContext().getSession();
String nickName=request.getParameter("userName");
MD5 md5=MD5.getInstance();
try {
Memberinfo member=memberService.findMemberinfoByName(nickName);
if(member==null){
throw new MemberServiceException("用户不存在!");
}
if(!member.getPasswordquestion().equals(request.getParameter("passwdQuestion"))){
throw new MemberServiceException("密码提示问题不正确!");
}
if(!member.getPasswordanswer().equals(request.getParameter("passwdAnswer"))){
throw new MemberServiceException("密码提示答案不正确!");
}
String message=memberService.findNewPasswd();
System.out.println("新密码是"+message);
session.put("message", message);
member.setPassword(md5.getMD5ofStr(message));
memberService.saveOrUpDate(member);
} catch (MemberServiceException e) {
e.printStackTrace();
addActionError(e.getMessage());
}
return "success";
}
//通过点击自己的"用户名" 或"管理个性化空间" 判断该用户有没有创建自己的个性空间,如果有则进入
//他的空间如果没有则提示
public String mySpaceMemberinfo(){
HttpServletRequest request=ServletActionContext.getRequest();
Map session = ActionContext.getContext().getSession();
Memberinfo member=(Memberinfo) session.get("memberinfo");
Memberspace memberspace=member.getMemberspace();
if(memberspace==null){
return "false";
}
System.out.println(member.getMemberspace().getIcon());
return "success";
}
//在排行榜中点击别人的用户名判断该用户有没有创建自己的个性空间,如果有则进入
//他的空间如果没有则提示
public String otherSpaceMemberinfo(){
HttpServletRequest request=ServletActionContext.getRequest();
Map session = ActionContext.getContext().getSession();
session.remove("othermemberspace");
String nickName=request.getParameter("memberName");
System.out.println("第三发送发的"+nickName);
try {
Memberinfo otherMember=memberService.findMemberinfoByName(nickName);
if(otherMember.getMemberspace()==null){
return "false";
}
System.out.println(otherMember.getMemberspace().getIcon());
session.put("othermemberspace", otherMember);
} catch (MemberServiceException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return "success";
}
//创建个人空间
public String createSpace() throws Exception{
Map session = ActionContext.getContext().getSession();
Memberinfo member = (Memberinfo) session.get("memberinfo");
HttpServletRequest request=ServletActionContext.getRequest();
String opinion=request.getParameter("opinion");
String runtime=request.getParameter("runtime");
String runhabit=request.getParameter("runhabit");
String runstar=request.getParameter("runstar");
String cellphone=request.getParameter("cellphone");
String runplace=request.getParameter("runplace");
try {
Memberspace space = member.getMemberspace();
if(space==null){
space=new Memberspace();
}
space.setOpinion(opinion);
space.setCellphone(cellphone);
space.setRunhabit(runhabit);
space.setRunplace(runplace);
space.setRuntime(runtime);
space.setRunstar(runstar);
String pathtemp=request.getRealPath("/");
File dir=new File(pathtemp+"/images/"+member.getNickname());
if(!dir.exists()){
dir.mkdir();
}
try {
FileInputStream fis=new FileInputStream(icon);
FileOutputStream fos=new FileOutputStream(dir+"/"+iconFileName);
System.out.println(iconFileName);
byte buffer[]=new byte[8192];
int count=0;
while((count=fis.read(buffer, 0, buffer.length))!=-1)
fos.write(buffer, 0, count);
fis.close();
fos.close();
} catch (Exception e) {
//TODO Auto-generated catch block
e.printStackTrace();
}
space.setIcon("/images/"+member.getNickname()+"/"+iconFileName);
System.out.println("lsadjf所看到附加列所看到"+icon);
member.setMemberspace(space);
space.setMemberinfo(member);
memberService.saveOrUpDate(member);
session.put("memberinfo", member);
return "success";
} catch (MemberServiceException e) {
e.printStackTrace();
addActionError(e.getMessage());
}
return "false";
}
public String getAuthCode() {
return authCode;
}
public void setAuthCode(String authCode) {
this.authCode = authCode;
}
public String getProvinceCity() {
return provinceCity;
}
public void setProvinceCity(String provinceCity) {
this.provinceCity = provinceCity;
}
public String getPasswd() {
return passwd;
}
public void setPasswd(String passwd) {
this.passwd = passwd;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public boolean isAutoLogin() {
return false;
}
public void setAutoLogin(boolean autoLogin) {
this.autoLogin = autoLogin;
}
public File getIcon() {
return icon;
}
public void setIcon(File icon) {
this.icon = icon;
}
public String getIconFileName() {
return iconFileName;
}
public void setIconFileName(String iconFileName) {
this.iconFileName = iconFileName;
}
}
分享到:
相关推荐
"http upload image demo"是一个示例项目,它展示了如何在Android中通过HTTP协议上传小尺寸的图片。这里我们将详细探讨这个过程中的关键知识点。 首先,我们需要了解HTTP协议。HTTP(超文本传输协议)是互联网上...
"Auto Upload Image" 文件可能是实现自动上传功能的主要脚本文件,它可能包含用JavaScript编写的代码,用于监听文件输入元素的变化,选择图片后立即触发上传过程。 **详细知识点** 1. **HTML5 File API**: 图片...
HTMLEditor控件是一个功能完整的富文本编辑器。...1、文本格式化,包括通过样式控制粗体、斜体、下划线和删除线 2、段落设置,如格式、字体家族、字体大小 3、前景色和背景色 4、文本缩进 5、项目符号和编号 ...
3.1 Topology to upload image ...........................................................................................................19 3.2 Upload bootloader image.....................................
('image.upload') }}" method="POST" enctype="multipart/form-data"> @csrf <input type="file" name="image"> 上传 ``` 别忘了在表单中添加`@csrf`指令,以防止跨站请求伪造(CSRF)攻击。 接下来,我们在...
在Laravel框架中进行...Route::post('/upload', 'ImageController@upload')->name('upload.image'); ``` 现在我们需要创建一个控制器来处理上传逻辑。运行以下Artisan命令生成一个新的`ImageController`: ```bash ...
【标题】"image-upload.zip" 是一个压缩包文件,它包含了一个完整的前端代码实现,用于支持大文件的断点续传功能。这个解决方案是基于百度的Webuploader组件,旨在优化和提升用户在上传大型图像或其他文件时的体验。...
文件上传是Web中常见的功能,选择性也很多,比如将文件上传到oss等类似的文件服务器上,这种方式成本比较高。文件的上传和显示操作比较简单。另外就是在文件上传到项目路径的静态资源文件夹resources/下。...
开源项目-olahol-go-imageupload#go-imageupload.zip,go-imageupload: Gracefully handle image uploading and thumbnail creation.
为了提高用户体验,"Imageupload"项目可能还实现了进度条显示,利用XMLHttpRequest或Fetch API的upload事件监听上传进度。此外,错误处理机制也是必不可少的,比如处理网络中断、文件类型限制、文件大小超出限制等...
标题中的“image upload view”指的是一个网页应用的功能模块,它允许用户在上传图片到服务器之前进行预览。这种功能在网站或应用中很常见,尤其是涉及到用户需要上传个人照片、产品图片或者其他图像资料的地方。它...
1. `HTTP_Image_Upload_ActiveX_5.06.dll`:这是ActiveX控件的主要文件,包含了实现图像上传功能的代码。 2. `readme.txt`:可能包含关于如何在网页中集成和使用控件的说明,以及任何兼容性或限制信息。 3. `sample....
message.error('Please upload an image file!'); return false; } if (file.size / 1024 > 5) { message.error('Image size should not exceed 5MB!'); return false; } return true; } ``` 此外,Ant ...
$('.thumbnail_image_upload').thumbnail_image_upload( { width :" 100 % ", height:" 100 % ", text: " Upload Image Here ", bg: 'f5f5f5', color: '00000' }); [removed] 执照 麻省理工学院 :...