无意义-wd7

AjaxController.java

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

package

 

 

com.hzau.information.web.controller;

 

import

 

 

java.io.IOException;

 

import

 

 

javax.servlet.http.HttpServletRequest;

import

 

 

javax.servlet.http.HttpServletResponse;

 

import

 

 

org.springframework.web.servlet.ModelAndView;

import

 

 

org.springframework.web.servlet.mvc.multiaction.MultiActionController;

 

import

 

 

com.hzau.information.json.JsonArray;

import

 

 

com.hzau.information.json.JsonObject;

 

public

 

 

class AjaxController extends

MultiActionController {

 

 

 

 

public

ModelAndView imageUpload(HttpServletRequest req,

HttpServletResponse res) {

System.

 

out.println("imageUpload"

);

 

// DataInputStream in;

// try {

// in = new DataInputStream(req.getInputStream());

// DataInputStream in1 = in;

// int formDataLength = req.getContentLength();

// byte dataBytes[] = new byte[formDataLength];

// int byteRead = 0;

// int totalBytesRead = 0;

//

// } catch (IOException e1) {

// //

// e1.printStackTrace();

// }

 

 

 

 

try

{

res.getWriter().write(localUserProfile());

}

 

catch

(IOException e) {

e.printStackTrace();

}

 

 

return null

;

}

 

 

 

public

ModelAndView getUserProfile(HttpServletRequest req,

HttpServletResponse res) {

System.

 

out.println("getUserProfile"

);

 

 

try

{

res.getWriter().write(localUserProfile());

}

 

catch

(IOException e) {

e.printStackTrace();

}

 

 

return null

;

}

 

 

 

 

public

ModelAndView getEditUserProfile(HttpServletRequest req,

HttpServletResponse res) {

System.

 

out.println("getUserProfile"

);

 

 

try

{

res.getWriter().write(localEditUserProfile());

}

 

catch

(IOException e) {

e.printStackTrace();

}

 

 

return null

;

}

 

 

 

public

String localUserProfile() {

JsonArray jsonArray =

 

new JsonArray("jsonData"

);

JsonObject obj =

 

new

JsonObject();

obj.putData(

 

"username", "ddd"

);

obj.putData(

 

"imgLink", "/Android_BBS/images/up_to_something.jpg"

);

obj.putData(

 

"postCount", "3"

);

obj.putData(

 

"level", "2"

);

obj.putData(

 

"score", "123"

);

obj.putData(

 

"visited", "123"

);

jsonArray.addJsonObject(obj);

System.

 

out

.println(jsonArray.toString());

 

 

 

return

jsonArray.toString();

}

 

 

 

public

String localEditUserProfile() {

System.

 

out.println("localEditUserProfile"

);

JsonArray jsonArray =

 

new JsonArray("jsonData"

);

JsonObject obj =

 

new

JsonObject();

obj.putData(

 

"username", "ddd"

);

obj.putData(

 

"imgLink", "/Android_BBS/images/up_to_something.jpg"

);

obj.putData(

 

"postCount", "3"

);

obj.putData(

 

"level", "2"

);

obj.putData(

 

"contribute", "123"

);

obj.putData(

 

"registerDate", "123"

);

jsonArray.addJsonObject(obj);

System.

 

out

.println(jsonArray.toString());

 

 

 

return

jsonArray.toString();

}

}

 

 

PostController.java

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

package

 

com.hzau.information.web.controller;

 

import

 

java.io.IOException;

import

 

java.text.SimpleDateFormat;

import

 

java.util.ArrayList;

import

 

java.util.Comparator;

import

 

java.util.Date;

import

 

java.util.HashSet;

import

 

java.util.Iterator;

import

 

java.util.List;

import

 

java.util.Set;

import

 

java.util.TreeSet;

 

import

 

javax.servlet.http.HttpServletRequest;

import

 

javax.servlet.http.HttpServletResponse;

 

import

 

org.springframework.web.servlet.ModelAndView;

import

 

org.springframework.web.servlet.mvc.multiaction.MultiActionController;

 

import

 

com.hzau.information.domain.Comment;

import

 

com.hzau.information.domain.Post;

import

 

com.hzau.information.domain.User;

import

 

com.hzau.information.json.JsonArray;

import

 

com.hzau.information.json.JsonObject;

import

 

com.hzau.information.service.BusinessService;

 

public

 

class PostController extends MultiActionController{

 

private BusinessService service=new BusinessService();

 

 

public ModelAndView view(HttpServletRequest req, HttpServletResponse res){

String postId=req.getParameter(

"postId");

ModelAndView model=

new ModelAndView("post_detail");

model.addObject(

"postId", postId);

 

return model;

}

 

 

public ModelAndView reply(HttpServletRequest req, HttpServletResponse res){

String postId=req.getParameter(

"postId");

Long postIdLong=Long.parseLong(postId);

 

String l_strflag1=req.getParameter(

"pageSequence");

String l_strflag2=(String)req.getSession().getAttribute(

"pageSequence");

System.

out.println(l_strflag1+" "+l_strflag1);

 

if(l_strflag1.equals(l_strflag2)){

String commentContent=req.getParameter(

"commentContent");

String username=((User)req.getSession().getAttribute(

"user")).getUserName();

 

Comment comment=

new Comment();

comment.setIssueTime(

new Date());

comment.setContent(commentContent);

 

User user=

service.getUserByName(username);

comment.setUserId(user.getId());

 

service.savePost(postIdLong,comment);

}

 

ModelAndView model=

new ModelAndView("post_detail");

model.addObject(

"postId", postId);

 

return model;

 

}

 

 

public ModelAndView post(HttpServletRequest req, HttpServletResponse res){

ModelAndView model=

new ModelAndView("post_sum");

String username=req.getParameter(

"username");

String titleInput=req.getParameter(

"titleInput");

String postContent=req.getParameter(

"postContent");

 

Post post=

new Post();

post.setCommentCount(0);

post.setComments(

new HashSet<Comment>());

post.setContent(postContent);

 

User user=

service.getUserByName(username);

 

if(user.getPosts()==null){

user.setPosts(

new ArrayList<Post>());

}

user.getPosts().add(post);

post.setPoster(user.getId());

post.setPostTime(

new Date());

post.setReadCount(0);

post.setTitle(titleInput);

 

 

service.savePost(post);

 

System.

out.println(username+" /n"+titleInput+" /n"+postContent);

 

return model;

}

 

 

public ModelAndView viewSumm(HttpServletRequest req, HttpServletResponse res){

 

 

return new ModelAndView("post_sum");

}

 

 

 

 

 

 

 

 

 

public ModelAndView getPostDetails(HttpServletRequest req, HttpServletResponse res){

String postId=req.getParameter(

"postId");

// Long postIdLong=0l;

// if(postId==null&&postId==""){

// return null;

// }else {

// postIdLong=Long.parseLong(postId);

// }

// Post post=service.getPostById(postIdLong);

// if(post==null){

// return null;

// }

// User user=service.getUserById(post.getPoster());

 

 

try {

// res.getWriter().write(buildPostJson(post,user));

res.getWriter().write(populate());

}

catch (IOException e) {

e.printStackTrace();

}

 

return null;

}

 

 

public ModelAndView loadTopicIntr(HttpServletRequest req, HttpServletResponse res){

System.

out.println("loadTopicIntr");

String src=req.getContextPath()+

"/css/images/htc.gif'";

String topicIntr=

"<img src='"+src+"' style='float:left;margin:10px;'><div id='topic_title'>HTC Source Sharing!</div>" +

 

"<div id='postCount_cont'>Post:<span style='color:red'>24</span></div>" +

 

"<div id='postCount_cont'>Moderator:<span style='color:red'>Lichengri008</span></div>" +

 

"</div><div id='description'>HTC US offers innovative & feature rich mobile phones. Explore all HTC smartphones, get support, and find out where to buy the best cell phone for you.</div>";

 

 

try {

res.getWriter().write(topicIntr);

}

catch (IOException e) {

e.printStackTrace();

}

 

return null;

}

 

 

public ModelAndView getPostJson(HttpServletRequest req, HttpServletResponse res){

JsonArray jsonData=

new JsonArray("posts");

String start=req.getParameter(

"start");

String limit=req.getParameter(

"limit");

 

int startIndex=Integer.valueOf(start);

 

int limitIndex=Integer.valueOf(limit);

 

// List<Post> posts=service.findPostByTopicId(0l);

// int endIndex=startIndex+limitIndex<posts.size()?startIndex+limitIndex:posts.size();

// for(int i=startIndex;i<endIndex;i++){

// Post post=posts.get(i);

// JsonObject jsonObj=new JsonObject();

// SimpleDateFormat dateformat2=new SimpleDateFormat("yyyy-MM-dd HH:mm");

// String a2=dateformat2.format(post.getPostTime());

// String username=service.getUserById(post.getPoster()).getUserName();

// jsonObj.putData("title", post.getTitle());

// jsonObj.putData("poster", username);

// jsonObj.putData("viewReply", post.getReadCount()+"/"+post.getCommentCount());

// jsonObj.putData("latestReply",a2);

// jsonObj.putData("postId", post.getId());

// jsonData.addJsonObject(jsonObj);

// }

// JsonObject metaData=new JsonObject();

// metaData.putData("total",posts.size());

// String json="{"+metaData.toString().substring(1,metaData.toString().length()-1)+","+jsonData.toString().substring(1,jsonData.toString().length());

 

try {

res.getWriter().write(pop());

// System.out.println(json);

// res.getWriter().write(json);

}

catch (IOException e) {

e.printStackTrace();

}

 

return null;

}

 

 

public String buildPostJson(Post post,User user){

JsonArray jsonArray=

new JsonArray("jsonData");

 

JsonObject jsonObj=

new JsonObject();

jsonObj.putData(

"username", user.getUserName());

jsonObj.putData(

"user_link", "#");

jsonObj.putData(

"replay_count", post.getCommentCount()+"");

jsonObj.putData(

"view_count", post.getReadCount()+"");

jsonObj.putData(

"content", post.getContent());

jsonObj.putData(

"lastmod", post.getPostTime()+"");

jsonObj.putData(

"isPost", "true");

jsonObj.putData(

"title", post.getTitle());

jsonObj.putData(

"url", user.getPerProfile().getIconUrl());

jsonArray.addJsonObject(jsonObj);

 

Set<Comment> comments=post.getComments();

 

List<JsonObject> comentsJson=

null;

 

if(comments!=null&&comments.size()!=0){

comentsJson=buildCommentsByPost(sortedComment(post.getComments()));

}

 

if(comentsJson!=null&&comentsJson.size()!=0){

jsonArray.getJsonData().addAll(comentsJson);

}

System.

out.println(jsonArray);

 

return jsonArray.toString();

}

 

public List<JsonObject> buildCommentsByPost(Set<Comment> comments){

List<JsonObject> commentsJson=

new ArrayList<JsonObject>();

JsonObject jsonObj;

 

for (Iterator it = comments.iterator(); it.hasNext();) {

Comment com = (Comment) it.next();

User user=(User)

service.get(User.class, com.getUserId());

jsonObj =

new JsonObject();

jsonObj.putData(

"username", user.getUserName());

jsonObj.putData(

"user_link", "#");

jsonObj.putData(

"content", com.getContent());

jsonObj.putData(

"lastmod", com.getIssueTime()+"");

jsonObj.putData(

"isPost", "false");

jsonObj.putData(

"url", "/Android_BBS/images/zacks_grill.jpg");

commentsJson.add(jsonObj);

}

 

 

return commentsJson;

}

 

public Set<Comment> sortedComment(Set<Comment> source){

Set sortedComment =

new TreeSet(new Comparator<Comment>() {

 

public int compare(Comment o1, Comment o2) {

 

if(o1.getIssueTime().before(o2.getIssueTime())){

 

return -1;

}

else {

 

return 1;

}

}

})

sortedComment.addAll(source);

 

return sortedComment;

}

 

//For test

 

public String populate(){

JsonArray jsonArray=

new JsonArray("jsonData");

 

JsonObject jsonObj=

new JsonObject();

jsonObj.putData(

"username", "zack");

jsonObj.putData(

"user_link", "#");

jsonObj.putData(

"replay_count", "32");

jsonObj.putData(

"view_count", "123");

jsonObj.putData(

"content", "CSS defines fiS defines fiS defines fiS defines fiS defines fiS defines fiS defines fiS defines fiSnes fiS defines fiSnes fiS dines fiS defines fiS defines fiS defines fiSnes fiS defines fiSnes fiS dines fiS defines fiS defines fiS defines fiSnes fiS defines fiSnes fiS dines fiS defines fiS defines fiS defines fiSnes fiS defines fiSnes fiS dines fiS defines fiS defines fiS defines fiSnes fiS defines fiSnes fiS dines fiS defines fiS defines fiS defines fiSnes fiS defines fiSnes fiS dines fiS defines fiS defines fiS defines fiSnes fiS defines fiSnes fiS dines fiS defines fiS defines fiS defines fiSnes fiS defines fiSnes fiS dines fiS defines fiS defines fiS defines fiSnes fiS defines fiSnes fiS dines fiS defines fiS defines fiS defines fiSnes fiS defines fiSnes fiS dines fiS defines fiS defines fiS defines fiSnes fiS defines fiSnes fiS dines fiS defines fiS defines fiS defines fiSnes fiS defines fiSnes fiS dines fiS defines fiS defines fiS defines fiSnes fiS defines fiSnes fiS dines fiS defines fiS defines fiS defines fiSnes fiS defines fiSnes fiS dines fiS defines fiS defines fiS defines fiSnes fiS defines fiSnes fiS dines fiS defines fiS defines fiS defines fiSnes fiS defines fiSnes fiS dines fiS defines fiS defines fiS defines fiSnes fiS defines fiSnes fiS dines fiS defines fiS defines fiS defines fiSnes fiS defines fiSnes fiS dines fiS defines fiS defines fiS defines fiSnes fiS defines fiSnes fiS dines fiS defines fiS defines fiS defines fiSnes fiS defines fiSnes fiS dines fiS defines fiS defines fiS defines fiSnes fiS defines fiSnes fiS dines fiS defines fiS defines fiS defines fiSnes fiS defines fiSnes fiS dines fiS defines fiS defines fiS defines fiSnes fiS defines fiSnes fiS dines fiS defines fiS defines fiS defines fiSnes fiS defines fiSnes fiS dines fiS defines fiS defines fiS defines fiSnes fiS defines fiSnes fiS dines fiS defines fiS defines fiS defines fiSnes fiS defines fiSnes fiS dines fiS defines fiS defines fiS defines fiSnes fiS defines fiSnes fiS dines fiS defines fiS defines fiS defines fiSnes fiS defines fiSnes fiS dines fiS defines fiS defines fiS defines fiSnes fiS defines fiSnes fiS dines fiS defines fiS defines fiS defines fiSnes fiS defines fiSnes fiS dines fiS defines fiS defines fiS defines fiSnes fiS defines fiSnes fiS dines fiS defines fiS defines fiS defines fiSnes fiS defines fiSnes fiS dines fiS defines fiS defines fiS defines fiSnes fiS defines fiSnes fiS dines fiS defines fiS defines fiS defines fiSnes fiS defines fiSnes fiS dines fiS defines fiS defines fiS defines fiSnes fiS defines fiSnes fiS dines fiS defines fiS defines fiS defines fiSnes fiS defines fiSnes fiS dines fiS defines fiS defines fiS defines fiSnes fiS defines fiSnes fiS dines fiS defines fiS defines fiS defines fiSnes fiS defines fiSnes fiS dines fiS defines fiS defines fiS defines fiSnes fiS defines fiSnes fiS dines fiS defines fiS defines fiS defines fiSnes fiS defines fiSnes fiS dines fiS defines fiS defines fiS defines fiSnes fiS defines fiSnes fiS dines fiS defines fiS defines fiS defines fiSnes fiS defines fiSnes fiS dines fiS defines fiS defines fiS defines fiSnes fiS defines fiSnes fiS dines fiS defines fiS defines fiS defines fiSnes fiS defines fiSnes fiS dines fiS defines fiS defines fiS defines fiSnes fiS defines fiSnes fiS dines fiS defines fiS defines fiS defines fiSnes fiS defines fiSnes fiS dines fiS defines fiS defines fiS defines fiSnes fiS defines fiSnes fiS dines fiS defines fiS defines fiS defines fiSnes fiS defines fiSnes fiS dines fiS defines fiS defines fiS defines fiSnes fiS defines fiSnes fiS dines fiS defines fiS defines fiS defines fiSnes fiS defines fiSnes fiS dines fiS defines fiS defines fiS defines fiSnes fiS defines fiSnes fiS dines fiS defines fiS defines fiS defines fiSnes fiS defines fiSnes fiS dines fiS defines fiS defines fiS defines fiSnes fiS defines fiSnes fiS dines fiS defines fiS defines fiS defines fiSnes fiS defines fiSnes fiS dines fiS defines fiS defines fiS defines fiSnes fiS defines fiSnes fiS dines fiS defines fiS defines fiS defines fiSnes fiS defines fiSnes fiS defines fiSnes fiS defines fiSnes fiS defines fiSnes fiS defines fiSnes fiS defines fiSnes fiS defines fiSnes fiS defines fiSnes fiS defines fiSnes fiS defines fiSnes fiS defines fiSnes fiS defines fiSnes fiS defines fiSnes fiS defines fiSnes fiS defines fiSnes fiS defines fiSnes fiS defines fiSnes fiS defines fiSnes fiS defines fiSnes fiS defines fiSnes fiS defines fiSnes fiS defines fiSnes fiS defines fiSnes fiS defines fiSnes fiS defines fiSnes fiS defines fiSnes fiS defines fiSnes fiS defines fiSnes fiS defines fiSnes fiS defines fiSnes fiS defines fiSnes fiS defines fiSnes fiS defines fiSnes fiS defines fiSnes fiS defines fiSnes fiS defines fiSnes fiS defines fiSnes fiS defines fiSnes fiS defines fiSnes fiS defines fiSnes fiS defines fiSnes fiS defines fiSnes fiS defines fiSnes fiS defines fiSnes fiS defines fiSnes fiS defines fiS defines fiS defines fiS defines fiS defines file!");

jsonObj.putData(

"lastmod", "1291155496000");

jsonObj.putData(

"isPost", "true");

jsonObj.putData(

"title", "The First Post!!!");

jsonObj.putData(

"url", "/Android_BBS/images/default_pro.bmp");

jsonArray.addJsonObject(jsonObj);

 

jsonObj=

new JsonObject();

jsonObj.putData(

"username", "zacks_grill");

jsonObj.putData(

"user_link", "#");

jsonObj.putData(

"content", "Good Job!Good Job!Good Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Jod Job!Good Job!Good Job!Good Job!Good Job!Good Job!Good Job!Good Job!Good Job!Good Job!Good Job!");

jsonObj.putData(

"lastmod", "1291155496000");

jsonObj.putData(

"isPost", "false");

jsonObj.putData(

"url", "/Android_BBS/images/zacks_grill.jpg");

jsonArray.addJsonObject(jsonObj);

 

jsonObj=

new JsonObject();

jsonObj.putData(

"username", "up_to_something");

jsonObj.putData(

"user_link", "#");

jsonObj.putData(

"content", "Good Job Ge Mao!");

jsonObj.putData(

"lastmod", "1291155496000");

jsonObj.putData(

"isPost", "false");

jsonObj.putData(

"url", "/Android_BBS/images/up_to_something.jpg");

jsonArray.addJsonObject(jsonObj);

 

System.

out.println(jsonArray);

 

return jsonArray.toString();

}

 

 

public String pop(){

//public static void main(String args[]){

JsonArray jsonArray=

new JsonArray("posts");

JsonObject jsonObj=

new JsonObject();

SimpleDateFormat dateformat2=

new SimpleDateFormat("yyyy-MM-dd HH:mm");

String a2=dateformat2.format(

new Date());

jsonObj.putData(

"title", "fdsdf");

jsonObj.putData(

"poster", "lichengri");

jsonObj.putData(

"viewReply", 3+"/"+2);

jsonObj.putData(

"latestReply",a2);

jsonArray.addJsonObject(jsonObj);

 

JsonObject metaData=

new JsonObject();

metaData.putData(

"total",1);

String json=

"{"+metaData.toString().substring(1,metaData.toString().length()-1)+","+jsonArray.toString().substring(1,jsonArray.toString().length());

System.

out.println(json);

 

return json;

}

}

UserController.java

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

package

 

 

 

com.hzau.information.web.controller;

 

import

 

 

 

java.io.File;

import

 

 

 

java.io.IOException;

import

 

 

 

java.util.ArrayList;

import

 

 

 

java.util.Date;

import

 

 

 

java.util.Iterator;

import

 

 

 

java.util.List;

 

import

 

 

 

javax.servlet.http.HttpServletRequest;

import

 

 

 

javax.servlet.http.HttpServletResponse;

 

import

 

 

 

org.apache.commons.fileupload.FileItem;

import

 

 

 

org.apache.commons.fileupload.FileItemFactory;

import

 

 

 

org.apache.commons.fileupload.disk.DiskFileItemFactory;

import

 

 

 

org.apache.commons.fileupload.servlet.ServletFileUpload;

import

 

 

 

org.springframework.web.servlet.ModelAndView;

import

 

 

 

org.springframework.web.servlet.mvc.multiaction.MultiActionController;

 

import

 

 

 

com.hzau.information.domain.PersonalProfile;

import

 

 

 

com.hzau.information.domain.SystemProfile;

import

 

 

 

com.hzau.information.domain.User;

import

 

 

 

com.hzau.information.json.JsonArray;

import

 

 

 

com.hzau.information.json.JsonObject;

import

 

 

 

com.hzau.information.service.BusinessService;

 

public

 

 

 

class UserController extends

MultiActionController {

 

 

 

private BusinessService service

;

 

 

 

public

ModelAndView login(HttpServletRequest req, HttpServletResponse res) {

String userName = (String) req.getParameter(

 

"user"

);

String password = (String) req.getParameter(

 

"password"

);

 

 

service = new

BusinessService();

User user =

 

service

.getUserByName(userName);

System.

 

out.println("Parameter: " + userName + " "

+ password);

String data =

 

""

;

 

 

if (user == null

) {

 

 

try

{

data =

 

"{status:'The user name is not exist!'}"

;

res.setContentType(

 

"text/json; charset=UTF-8"

);

res.getWriter().write(data);

 

 

return null

;

}

 

catch

(IOException e) {

e.printStackTrace();

}

}

 

else if

(!user.getPassword().equals(password)) {

 

 

try

{

data =

 

"{status:'Wrong Password!'}"

;

res.setContentType(

 

"text/json; charset=UTF-8"

);

res.getWriter().write(data);

 

 

return null

;

}

 

catch

(IOException e) {

e.printStackTrace();

}

}

 

else

{

 

 

try

{

data =

 

"{status:'success',userName:'"

+ user.getUserName()

+

 

"'}"

;

res.setContentType(

 

"text/json; charset=UTF-8"

);

req.getSession().setAttribute(

 

"user"

, user);

res.getWriter().write(data);

 

 

return null

;

}

 

catch

(IOException e) {

e.printStackTrace();

}

}

 

 

return null

;

}

 

 

 

public

ModelAndView viewUser(HttpServletRequest req, HttpServletResponse res) {

ModelAndView model =

 

new ModelAndView("view_user"

);

 

 

return

model;

}

 

 

 

public

ModelAndView register(HttpServletRequest req, HttpServletResponse res) {

String userName = (String) req.getParameter(

 

"user"

);

String password = (String) req.getParameter(

 

"password"

);

String email = (String) req.getParameter(

 

"email"

);

 

 

service = new

BusinessService();

User user =

 

service

.getUserByName(userName);

 

String data =

 

""

;

 

 

if (user != null

) {

 

 

try

{

data =

 

"{status:'The user name is existing!'}"

;

res.setContentType(

 

"text/json; charset=UTF-8"

);

res.getWriter().write(data);

 

 

return null

;

}

 

catch

(IOException e) {

e.printStackTrace();

}

}

 

else

{

user =

 

new

User();

user.setuserName(userName);

user.setPassword(password);

PersonalProfile perProfile =

 

new

PersonalProfile();

perProfile.setEmail(email);

perProfile.setIconUrl(

 

"/Android_BBS/images/default_pro.bmp"

);

perProfile.setName(userName);

perProfile.setNickName(userName);

user.setPerProfile(perProfile);

SystemProfile sp =

 

new

SystemProfile();

sp.setContribute(0);

sp.setLevel(0);

sp.setOnLineTime(0l);

sp.setRegisterDate(

 

new

Date());

user.setSysProfile(sp);

 

 

 

try

{

 

 

 

boolean flag = service

.saveUser(user);

 

 

if

(flag) {

data =

 

"{status:'success'}"

;

res.setContentType(

 

"text/json; charset=UTF-8"

);

req.setAttribute(

 

"user"

, user);

res.getWriter().write(data);

}

 

else

{

data =

 

"{status:'Error occured when save user!'}"

;

res.setContentType(

 

"text/json; charset=UTF-8"

);

}

 

}

 

catch

(IOException e) {

e.printStackTrace();

}

}

 

 

return null

;

}

 

 

 

public

ModelAndView getUserProfile(HttpServletRequest req,

HttpServletResponse res) {

System.

 

out.println("getUserProfile"

);

 

 

try

{

res.getWriter().write(localUserProfile());

}

 

catch

(IOException e) {

e.printStackTrace();

}

 

 

return null

;

}

 

 

 

public

String localUserProfile() {

JsonArray jsonArray =

 

new JsonArray("jsonData"

);

JsonObject obj =

 

new

JsonObject();

obj.putData(

 

"username", "ddd"

);

obj.putData(

 

"imgLink", "/Android_BBS/images/up_to_something.jpg"

);

obj.putData(

 

"postCount", "3"

);

obj.putData(

 

"level", "2"

);

obj.putData(

 

"score", "123"

);

obj.putData(

 

"visited", "123"

);

jsonArray.addJsonObject(obj);

System.

 

out

.println(jsonArray.toString());

 

 

 

return

jsonArray.toString();

}

 

 

 

public

ModelAndView saveEditProfile(HttpServletRequest req,

HttpServletResponse res) {

System.

 

out.println("saveEditProfile"

);

 

String basePath = getServletContext().getRealPath(

 

"/Upload"

);

 

 

boolean

isMultipart = ServletFileUpload.isMultipartContent(req);

 

 

 

if (isMultipart == true

) {

 

 

try

{

req.setCharacterEncoding(

 

"UTF-8"

);

FileItemFactory factory =

 

new

DiskFileItemFactory();

ServletFileUpload upload =

 

new

ServletFileUpload(factory);

 

List<FileItem> fileItems = upload.parseRequest(req);

Iterator<FileItem> iter = fileItems.iterator();

 

 

 

while

(iter.hasNext()) {

FileItem item = (FileItem) iter.next();

 

 

 

if

(item.isFormField()) {

String name = item.getFieldName();

String value = item.getString();

}

 

else

{

String fileName = item.getName();

 

 

if (fileName != null

) {

File fullFile =

 

new

File(item.getName());

 

 

if

(fullFile.exists()) {

File fileOnServer =

 

new

File(basePath, fullFile

.getName());

item.write(fileOnServer);

 

}

}

}

}

}

 

catch

(Exception e) {

e.printStackTrace();

}

}

 

else

{

System.

 

out.println("the enctype must be multipart/form-data"

);

}

 

List<String> fileListInServer =

 

new

ArrayList<String>();

 

File dir =

 

new

File(basePath);

String[] children = dir.list();

 

 

if (children != null

) {

 

 

for (int i = 0; i < children.length

; i++) {

fileListInServer.add(children[i]);

}

}

req.setAttribute(

 

"downloadList"

, fileListInServer);

 

 

 

return new ModelAndView("profile_edit"

);

 

}

 

}

 

 

 

 

 

HibernateUtil.java

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

package

 

 

com.hzau.information;

 

import

 

 

org.hibernate.SessionFactory;

import

 

 

org.hibernate.cfg.Configuration;

 

public

 

 

class

HibernateUtil {

 

 

private static final SessionFactory sessionFactory

;

 

 

 

static

{

 

 

try

{

 

 

sessionFactory=new

Configuration().configure().buildSessionFactory();

}

 

catch

(Throwable ex){

System.

 

err.println("Initial SessionFactory creation failed."

+ex);

 

 

throw new

ExceptionInInitializerError(ex);

}

}

 

 

 

public static

SessionFactory getSessionFactory(){

 

 

return sessionFactory

;}

}

 

 

hibernate.cfg.xml

<?

 

xml version="1.0" encoding="UTF-8"?>

<!

 

DOCTYPE hibernate-configuration PUBLIC

"-//Hibernate/Hibernate Configuration DTD 3.0//EN"

 

"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"

 

>

 

<

 

hibernate-configuration>

 

<session-factory>

 

<property name="connection.driver_class">com.mysql.jdbc.Driver</property>

 

<property name="connection.url">jdbc:mysql://localhost/test</property>

 

<property name="connection.username">root</property>

 

<property name="connection.password"></property>

 

<property name="dialect">org.hibernate.dialect.MySQLDialect</property>

 

 

<property name="hibernate.hbm2ddl.auto">update</property>

 

<property name="show_sql">true</property>

 

 

<mapping resource="com/hzau/information/domain/SystemProfile.hbm.xml" />

 

<mapping resource="com/hzau/information/domain/User.hbm.xml" />

 

<mapping resource="com/hzau/information/domain/PersonalProfile.hbm.xml" />

 

<mapping resource="com/hzau/information/domain/Post.hbm.xml"/>

 

<mapping resource="com/hzau/information/domain/Comment.hbm.xml"/>

 

<mapping resource="com/hzau/information/domain/Topic.hbm.xml"/>

 

<mapping resource="com/hzau/information/domain/Area.hbm.xml"/>

 

 

</session-factory>

</

 

hibernate-configuration>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值