ssh架构 简易博客

不会做美工,,so ,界面很丑。

com.blog.domain

  Article.java

 1 package com.blog.domain;
 2 
 3 import java.io.Serializable;
 4 import java.sql.Timestamp;
 5 
 6 public class Article implements Serializable {
 7 
 8     /**
 9      * 
10      */
11     private static final long serialVersionUID = 1L;
12     
13     private Integer id;
14     private String title;
15     private String  contents ;
16     private Character type; //O->原创;  R->转载;T->翻译
17     private User user;
18     private Timestamp postTime;
19     
20     
21     public Article() {
22     }
23     public Article(String title, String contents, Character type,
24             User user) {
25         super();
26         this.title = title;
27         this.contents = contents;
28         this.type = type;
29         this.user = user;
30     }
31     public Timestamp getPostTime() {
32         return postTime;
33     }
34     public void setPostTime(Timestamp postTime) {
35         this.postTime = postTime;
36     }
37     public Integer getId() {
38         return id;
39     }
40     public void setId(Integer id) {
41         this.id = id;
42     }
43     public String getTitle() {
44         return title;
45     }
46     public void setTitle(String title) {
47         this.title = title;
48     }
49     public String getContents() {
50         return contents;
51     }
52     public void setContents(String contents) {
53         this.contents = contents;
54     }
55     public Character getType() {
56         return type;
57     }
58     public void setType(Character type) {
59         this.type = type;
60     }
61     public User getUser() {
62         return user;
63     }
64     public void setUser(User user) {
65         this.user = user;
66     }
67 
68 }
View Code

  User.java

 1 package com.blog.domain;
 2 
 3 import java.io.Serializable;
 4 import java.util.Set;
 5 
 6 public class User implements Serializable{
 7     /**
 8      * 
 9      */
10     private static final long serialVersionUID = 1L;
11 
12     private Integer id;
13     private String userName;
14     private String passwd;
15     private Character sex;
16     //头像路径
17     private String portrait;
18     private Set<Article> userArt;
19     
20     
21     public User(String userName, String passwd, Character sex,
22             String portrait) {
23         super();
24         this.userName = userName;
25         this.passwd = passwd;
26         this.sex = sex;
27         this.portrait = portrait;
28     }
29     public User(Integer id, String passwd) {
30         super();
31         this.id = id;
32         this.passwd = passwd;
33     }
34     public User(){}
35     public Integer getId() {
36         return id;
37     }
38     public void setId(Integer id) {
39         this.id = id;
40     }
41     public String getUserName() {
42         return userName;
43     }
44     public void setUserName(String userName) {
45         this.userName = userName;
46     }
47     public String getPasswd() {
48         return passwd;
49     }
50     public void setPasswd(String passwd) {
51         this.passwd = passwd;
52     }
53     public Character getSex() {
54         return sex;
55     }
56     public void setSex(Character sex) {
57         this.sex = sex;
58     }
59     public String getPortrait() {
60         return portrait;
61     }
62     public void setPortrait(String portrait) {
63         this.portrait = portrait;
64     }
65     public Set<Article> getUserArt() {
66         return userArt;
67     }
68     public void setUserArt(Set<Article> userArt) {
69         this.userArt = userArt;
70     }
71     
72     
73     
74 
75 }
View Code

  Article.hbm.xml

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
 3 "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
 4 <hibernate-mapping package="com.blog.domain">
 5     <class name="Article" table="Articles" lazy="true">
 6         <id name="id" type="java.lang.Integer">
 7             <generator class="native"></generator>
 8          </id>
 9          <!--设置默认值为当前时间  -->
10          <timestamp name="postTime" column="postTime"></timestamp>
11          <property name="contents" type="text">
12              <column name="contents" ></column>
13          </property>
14         <!--  <property name="postTime" type="date"    >
15              <column name="postTime"  ></column>
16          </property> -->
17          <property name="title" type="text">
18              <column name="title"></column>
19          </property>
20          <property name="type" type="character">
21              <column name="type"></column>
22          </property>
23          <many-to-one name="user" column="user_id"> </many-to-one>
24     </class>
25     
26 </hibernate-mapping>
View Code

  User.hbm.xml

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
 3 "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
 4 <hibernate-mapping package="com.blog.domain">
 5     <class name="User" table="Users" lazy="true">
 6         <id name="id" type="java.lang.Integer">
 7             <generator class="native"></generator>
 8         </id>
 9         <property name="userName" type="java.lang.String" not-null="true">
10             <column name="userName" length="32"></column>
11         </property>
12         <property name="passwd" type="java.lang.String" not-null="true">
13             <column name="passwd" length="32"></column>
14         </property>
15         <property name="portrait" type="java.lang.String">
16             <column name="portrait" length="512"></column>
17         </property>
18         <property name="sex" type="java.lang.Character">
19             <column name="sex"></column>
20         </property>
21         <set name="userArt">
22             <key column="user_id"></key>
23             <one-to-many class="Article"/>
24         </set>
25     </class>
26     
27 </hibernate-mapping>
View Code

com.blog.service.base

  BaseServiceImp.java

 1 package com.blog.service.base;
 2 
 3 import java.io.Serializable;
 4 import java.util.List;
 5 
 6 import org.hibernate.Query;
 7 import org.hibernate.SessionFactory;
 8 import org.springframework.transaction.annotation.Transactional;
 9 
10 @Transactional
11 public class BaseServiceImp implements BaseServiceInter {
12     private SessionFactory sessionFactory;
13     
14     public SessionFactory getSessionFactory() {
15         return sessionFactory;
16     }
17 
18     public void setSessionFactory(SessionFactory sessionFactory) {
19         this.sessionFactory = sessionFactory;
20     }
21 
22     @SuppressWarnings("rawtypes")
23     @Override
24     public Object findById(Class clazz, Serializable id) {
25         // TODO Auto-generated method stub
26         return sessionFactory.getCurrentSession().get(clazz, id);
27     }
28 
29     @Override
30     public void delObj(Object obj) {
31         // TODO Auto-generated method stub
32         sessionFactory.getCurrentSession().delete(obj);
33     }
34 
35     @SuppressWarnings("rawtypes")
36     @Override
37     public List executeQuery(String hql, Object[] parameters) {
38         // TODO Auto-generated method stub
39 
40         Query query=this.sessionFactory.getCurrentSession().createQuery(hql);
41 
42         //注入?值
43         if(parameters!=null && parameters.length>0){
44             for(int i=0;i<parameters.length;i++){
45                 query.setParameter(i, parameters[i]);
46                 
47             }
48         }
49         
50         return query.list();
51     }
52 
53     @Override
54     public Object uniqueQuery(String hql, Object[] parameters) {
55         // TODO Auto-generated method stub
56         Query query=this.sessionFactory.getCurrentSession().createQuery(hql);
57         //给?赋值
58         if(parameters!=null && parameters.length>0){
59             for(int i=0;i<parameters.length;i++){
60                 query.setParameter(i, parameters[i]);
61             }
62         }
63         
64         return query.uniqueResult();
65     }
66 
67     @Override
68     public void addTo(Object obj) {
69         // TODO Auto-generated method stub
70         sessionFactory.getCurrentSession().save(obj);
71         
72     }
73 
74 }
View Code

  BaseServiceInter.java

 1 package com.blog.service.base;
 2 
 3 import java.io.Serializable;
 4 import java.util.List;
 5 
 6 public interface BaseServiceInter {
 7     @SuppressWarnings("rawtypes")
 8     public Object  findById(Class clazz,Serializable id);
 9 
10     public void delObj(Object obj);
11     
12     @SuppressWarnings("rawtypes")
13     public List executeQuery(String hql, Object[] parameters);
14 
15     public Object uniqueQuery(String hql, Object[] parameters);
16 
17     public void addTo(Object obj);
18 
19 
20 }
View Code

com.blog.service.imp

  ArticleServiceImp.java

 1 package com.blog.service.imp;
 2 
 3 import java.util.List;
 4 
 5 import com.blog.domain.Article;
 6 import com.blog.domain.User;
 7 import com.blog.service.base.BaseServiceImp;
 8 import com.blog.service.inter.ArticleServiceInter;
 9 
10 public class ArticleServiceImp extends BaseServiceImp implements
11         ArticleServiceInter {
12 
13     /**
14      * 显示指定用户的所有文章
15      */
16     @Override
17     public List<Article> showUserArticles(User user) {
18         // TODO Auto-generated method stub
19         String hql="from Article where user_id=? ";
20         Object []param={user.getId()};
21         return this.executeQuery(hql, param);
22     }
23     /**
24      * 显示所有用户的所有文章
25      */
26     @Override
27     public List<Article> showAllArticles() {
28         // TODO Auto-generated method stub
29         String hql="from Article";
30         return this.executeQuery(hql, null);
31     }
32 
33 }
View Code

  UserServiceImp.java

 1 package com.blog.service.imp;
 2 
 3 import org.springframework.transaction.annotation.Transactional;
 4 
 5 import com.blog.domain.User;
 6 import com.blog.service.base.BaseServiceImp;
 7 import com.blog.service.inter.UserServiceInter;
 8 
 9 @Transactional
10 public class UserServiceImp extends BaseServiceImp implements UserServiceInter {
11 
12 
13 
14     /**
15      * 验证用户
16      * @author frank
17      */
18     @Override
19     public User checkUser(User user) {
20         // TODO Auto-generated method stub
21         String hql="from User where id=? and passwd=?";
22         Object []param={user.getId(),user.getPasswd()};
23         System.out.println("########checkUser########");
24         System.out.println(user.getId()+" "+user.getPasswd());
25         User u= (User) this.uniqueQuery(hql, param);
26         if(u!=null){
27             return u;
28         }
29         else
30             return null;
31     }
32 
33 }
View Code

com.blog.service.inter

  ArticleServiceInter.java

 1 package com.blog.service.inter;
 2 
 3 import java.util.List;
 4 
 5 import com.blog.domain.Article;
 6 import com.blog.domain.User;
 7 import com.blog.service.base.BaseServiceInter;
 8 
 9 public interface ArticleServiceInter extends BaseServiceInter{
10 
11     public List<Article> showUserArticles(User user);
12     
13     public List<Article> showAllArticles();
14 }
View Code

  UserServiceInter.java

1 package com.blog.service.inter;
2 
3 import com.blog.domain.User;
4 import com.blog.service.base.BaseServiceInter;
5 
6 public interface UserServiceInter extends BaseServiceInter {
7     public User checkUser(User user);
8 
9 }
View Code

com.blog.web.action

  GoContentUiAction.java

 1 package com.blog.web.action;
 2 
 3 import java.util.List;
 4 
 5 
 6 
 7 
 8 
 9 
10 
11 
12 
13 import org.apache.struts2.ServletActionContext;
14 
15 import com.blog.domain.Article;
16 import com.blog.domain.User;
17 import com.blog.service.inter.ArticleServiceInter;
18 import com.opensymphony.xwork2.ActionContext;
19 import com.opensymphony.xwork2.ActionSupport;
20 
21 public class GoContentUiAction extends ActionSupport {
22 
23     /**
24      * 
25      */
26     private static final long serialVersionUID = 1L;
27     
28     private ArticleServiceInter articleService;
29 
30     public ArticleServiceInter getArticleService() {
31         return articleService;
32     }
33 
34     public void setArticleService(ArticleServiceInter articleService) {
35         this.articleService = articleService;
36     }
37 
38     public String UserBlog() throws Exception {
39         // TODO Auto-generated method stub
40         User user=(User) ActionContext.getContext().getSession().get("loginUser");
41         List<Article> list=articleService.showUserArticles(user);
42         //截取内容的前200个字符做为摘要
43         for(int i=0;i<list.size();i++){
44             if(list.get(i).getContents().length()>200)
45                 list.get(i).setContents(list.get(i).getContents().substring(0, 200));
46         }
47         //把当前登录用户的文章放入request
48         ServletActionContext.getRequest().setAttribute("arts", list);
49         return "userBlog";
50     }
51     
52     public String Register() throws Exception {
53         // TODO Auto-generated method stub
54         return "register";
55     }
56 
57     public String NewArt() throws Exception {
58         // TODO Auto-generated method stub
59         return "newArt";
60     }
61     
62 
63     public String ShowArtDet() throws Exception {
64         // TODO Auto-generated method stub
65         Integer id=Integer.parseInt(ServletActionContext.getRequest().getParameter("id"));
66         Article art=(Article) articleService.findById(Article.class, id);
67         ServletActionContext.getRequest().setAttribute("art", art);
68         return "showArtDet";
69     }
70 
71 }
View Code

  LoginAndLogoutAction.java

 1 package com.blog.web.action;
 2 
 3 import java.util.List;
 4 
 5 import org.apache.struts2.ServletActionContext;
 6 
 7 import com.blog.domain.Article;
 8 import com.blog.domain.User;
 9 import com.blog.service.inter.ArticleServiceInter;
10 import com.blog.service.inter.UserServiceInter;
11 import com.opensymphony.xwork2.ActionContext;
12 import com.opensymphony.xwork2.ActionSupport;
13 
14 public class LoginAndLogoutAction extends ActionSupport {
15 
16     /**
17      * 
18      */
19     private static final long serialVersionUID = 1L;
20     private UserServiceInter userService;
21     private ArticleServiceInter articleService;
22     private String userId;
23     private String passwd;
24 
25     public ArticleServiceInter getArticleService() {
26         return articleService;
27     }
28 
29     public void setArticleService(ArticleServiceInter articleService) {
30         this.articleService = articleService;
31     }
32 
33     public UserServiceInter getUserService() {
34         return userService;
35     }
36 
37     public void setUserService(UserServiceInter userService) {
38         this.userService = userService;
39     }
40     public String getUserId() {
41         return userId;
42     }
43 
44     public void setUserId(String userId) {
45         this.userId = userId;
46     }
47 
48     public String getPasswd() {
49         return passwd;
50     }
51 
52     public void setPasswd(String passwd) {
53         this.passwd = passwd;
54     }
55 
56     public String login() throws Exception {
57         // TODO Auto-generated method stub
58         User user=new User();
59         user.setId(Integer.parseInt(this.getUserId()));
60         user.setPasswd(this.getPasswd());
61         user=userService.checkUser(user);
62         //登录成功
63         if(user!=null){
64             List<Article> list=articleService.showAllArticles();
65             //截取内容的前200个字符做为摘要
66             for(int i=0;i<list.size();i++){
67                 if(list.get(i).getContents().length()>200)
68                     list.get(i).setContents(list.get(i).getContents().substring(0, 200));
69             }
70             //把所有用户的文章放入request
71             ServletActionContext.getRequest().setAttribute("arts", list);
72             ActionContext.getContext().getSession().put("loginUser", user);
73         }
74         return LOGIN;
75     }
76 
77     public String logout() throws Exception {
78         // TODO Auto-generated method stub
79         ActionContext.getContext().getSession().clear();
80         return LOGIN;
81     }
82 
83 }
View Code

  RegisterAction.java

  1 package com.blog.web.action;
  2 
  3 import java.io.File;
  4 import java.io.FileInputStream;
  5 import java.io.FileOutputStream;
  6 import java.util.UUID;
  7 
  8 import org.apache.struts2.ServletActionContext;
  9 
 10 import com.blog.domain.User;
 11 import com.blog.service.inter.UserServiceInter;
 12 import com.opensymphony.xwork2.ActionContext;
 13 import com.opensymphony.xwork2.ActionSupport;
 14 
 15 public class RegisterAction extends ActionSupport {
 16 
 17     /**
 18      * 
 19      */
 20     private static final long serialVersionUID = 1L;
 21 
 22     private UserServiceInter userService;
 23     private String savePath;
 24     
 25     private String userName;
 26     private String passwd;
 27     private Character sex;
 28     private File portrait;
 29     //封装上传文件类型及文件名
 30     private String portraitContentType;
 31     private String portraitFileName;
 32     
 33 
 34     
 35 
 36     public String getPortraitContentType() {
 37         return portraitContentType;
 38     }
 39 
 40     public void setPortraitContentType(String portraitContentType) {
 41         this.portraitContentType = portraitContentType;
 42     }
 43 
 44     public String getPortraitFileName() {
 45         return portraitFileName;
 46     }
 47 
 48     public void setPortraitFileName(String portraitFileName) {
 49         this.portraitFileName = portraitFileName;
 50     }
 51 
 52     // 接受struts.xml文件配置值的方法
 53     public void setSavePath(String value) {
 54         this.savePath = value;
 55     }
 56 
 57     // 获取上传文件的保存位置
 58     private String getSavePath() throws Exception {
 59         return ServletActionContext.getServletContext()
 60                 .getRealPath(savePath);
 61     }
 62 
 63 
 64 
 65     public String getUserName() {
 66         return userName;
 67     }
 68 
 69     public void setUserName(String userName) {
 70         this.userName = userName;
 71     }
 72 
 73     public String getPasswd() {
 74         return passwd;
 75     }
 76 
 77     public void setPasswd(String passwd) {
 78         this.passwd = passwd;
 79     }
 80 
 81     public Character getSex() {
 82         return sex;
 83     }
 84 
 85     public void setSex(Character sex) {
 86         this.sex = sex;
 87     }
 88 
 89     public File getPortrait() {
 90         return portrait;
 91     }
 92 
 93     public void setPortrait(File portrait) {
 94         this.portrait = portrait;
 95     }
 96 
 97     public UserServiceInter getUserService() {
 98         return userService;
 99     }
100 
101     public void setUserService(UserServiceInter userService) {
102         this.userService = userService;
103     }
104 
105     @Override
106     public String execute() throws Exception {
107         // TODO Auto-generated method stub
108         // 以服务器的文件保存地址和原文件名建立上传文件输出流
109         //防止重名,采用uuid作为保存文件名,并保留原文件的后缀名
110         String fileName=UUID.randomUUID().toString()+this.getPortraitFileName().substring(this.getPortraitFileName().lastIndexOf(".")) ;
111         
112         FileOutputStream fos = new FileOutputStream(
113                 getSavePath() + "/" +fileName);
114         FileInputStream fis = new FileInputStream(getPortrait());
115         byte[] buffer = new byte[1024];
116         int len = 0;
117         //写入
118         while ((len = fis.read(buffer)) > 0) {
119             fos.write(buffer, 0, len);
120         }
121         fos.close();
122         fis.close();
123         ActionContext.getContext().getSession().put("uploadFileName", fileName);
124         //保存用户信息到数据库
125         User user=new User(this.getUserName(),this.getPasswd(),this.getSex(),"uploadFiles/"+fileName);
126         userService.addTo(user);
127         //获取刚注册用户的id号
128         String hql="from User where id=(select max(id) from User)";
129         user=(User) userService.uniqueQuery(hql, null);
130         //将登录用户设置为当前用户
131         ActionContext.getContext().getSession().put("loginUser", user);
132         
133                 
134         return SUCCESS;
135     }
136 
137 
138 
139 }
View Code

  ReleaseAction.java

 1 package com.blog.web.action;
 2 
 3 import com.blog.domain.Article;
 4 import com.blog.domain.User;
 5 import com.blog.service.inter.ArticleServiceInter;
 6 import com.opensymphony.xwork2.ActionContext;
 7 import com.opensymphony.xwork2.ActionSupport;
 8 
 9 public class ReleaseAction extends ActionSupport {
10 
11     /**
12      * 
13      */
14     private static final long serialVersionUID = 1L;
15     private ArticleServiceInter articleService;
16     private String title;
17     private Character type;
18     private String contents;
19     
20     
21     public String getTitle() {
22         return title;
23     }
24 
25     public void setTitle(String title) {
26         this.title = title;
27     }
28 
29     public Character getType() {
30         return type;
31     }
32 
33     public void setType(Character type) {
34         this.type = type;
35     }
36 
37     public String getContents() {
38         return contents;
39     }
40 
41     public void setContents(String contents) {
42         this.contents = contents;
43     }
44 
45     public ArticleServiceInter getArticleService() {
46         return articleService;
47     }
48 
49     public void setArticleService(ArticleServiceInter articleService) {
50         this.articleService = articleService;
51     }
52 
53     @Override
54     public String execute() throws Exception {
55         // TODO Auto-generated method stub
56         User user=(User) ActionContext.getContext().getSession().get("loginUser");
57         Article art=new Article(title,contents,type,user);
58         articleService.addTo(art);
59         return SUCCESS;
60     }
61 
62 }
View Code

  RegisterAction-validation.xml

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <!DOCTYPE validators PUBLIC
 3         "-//OpenSymphony Group//XWork Validator  1.0.3//EN"
 4         "http://www.opensymphony.com/xwork/xwork-validator-1.0.3.dtd">
 5         <validators>
 6             <validator type="required">
 7                 <param name="fieldName">userName</param>
 8                 <message>username must not be null</message>
 9             </validator>
10             <validator type="required">
11                 <param name="fieldName">passwd</param>
12                 <message>password must not be null</message>
13             </validator>
14         
15         
16         </validators>
View Code

applicationContext.xml

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <beans
 3     xmlns="http://www.springframework.org/schema/beans"
 4     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 5     xmlns:p="http://www.springframework.org/schema/p"
 6     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd" xmlns:tx="http://www.springframework.org/schema/tx">
 7 
 8     <!-- 配置action -->
 9     <bean  id="loginAndLogout" scope="prototype" class="com.blog.web.action.LoginAndLogoutAction">
10         <property name="userService" ref="userServiceImp"></property>
11         <property name="articleService" ref="articleServiceImp"></property>
12     </bean>
13     <bean id="goContentUi" scope="prototype" class="com.blog.web.action.GoContentUiAction">
14         <property name="articleService" ref="articleServiceImp"></property>
15     </bean>
16     <bean id="doRegist" scope="prototype" class="com.blog.web.action.RegisterAction">
17         <property name="userService" ref="userServiceImp"></property>
18     </bean>
19     <bean id="releaseBlog" scope="prototype" class="com.blog.web.action.ReleaseAction">
20         <property name="articleService" ref="articleServiceImp"></property>
21     </bean>
22     
23     <!-- 配置service类 -->
24     <bean id="baseServiceImp" class="com.blog.service.base.BaseServiceImp" abstract="true">
25         <property name="sessionFactory" ref="sessionFactory"></property>
26     </bean>
27     <bean id="userServiceImp" class="com.blog.service.imp.UserServiceImp" parent="baseServiceImp"></bean>
28     <bean id="articleServiceImp" class="com.blog.service.imp.ArticleServiceImp" parent="baseServiceImp"></bean>
29     
30     <!-- 配置数据源 -->    
31     <bean id="dataSource"
32         class="org.apache.commons.dbcp.BasicDataSource">
33         <property name="url" value="jdbc:mysql://127.0.0.1:3306/blog"></property>
34         <property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
35         <property name="username" value="root"></property>
36         <property name="password" value="frank1994"></property>
37     </bean>
38     <!-- 配置会话工厂 -->
39     <bean id="sessionFactory"
40         class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
41         <property name="dataSource">
42             <ref bean="dataSource" />
43         </property>
44         <property name="hibernateProperties">
45             <props>
46                 <prop key="hibernate.dialect">
47                     org.hibernate.dialect.MySQLDialect
48                 </prop>
49                 <prop key="hibernate.show_sql" >true</prop>
50                 <prop key="hibernate.format_sql">true</prop>
51                 <prop key="hibernate.hbm2ddl.auto">
52                     update
53                 </prop>
54             </props>
55         </property>
56                 <property name="mappingResources">
57             <list>
58                 <value>com/blog/domain/User.hbm.xml</value>
59                 <value>com/blog/domain/Article.hbm.xml</value>
60             </list>
61         </property>
62     </bean>
63     <!-- 配置事务管理器 -->
64     <bean id="transactionManager"
65         class="org.springframework.orm.hibernate4.HibernateTransactionManager">
66         <property name="sessionFactory" ref="sessionFactory" />
67     </bean>
68     <!-- 开启事务 -->
69     <tx:annotation-driven transaction-manager="transactionManager" /></beans>
View Code

struts.xml

 1 <?xml version="1.0" encoding="UTF-8" ?>
 2 <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
 3 <struts>
 4     <package name="lee" extends="struts-default" namespace="/">
 5         <action name="*Action" class="loginAndLogout" method="{1}">
 6             <!-- 不管登录是否成功,都返回首页面 -->
 7             <result name="login">index.jsp</result>
 8         </action>
 9         <action name="go*Ui" class="goContentUi" method="{1}">
10         
11             <result name="userBlog">WEB-INF/page/userBlog.jsp</result>
12             <result name="register">WEB-INF/page/register.jsp</result>
13             <result name="newArt">WEB-INF/page/newArt.jsp</result>
14             <result name="showArtDet">WEB-INF/page/showArtDet.jsp</result>
15         </action>
16         <action name="doRegist" class="doRegist">
17             <param name="savePath">/uploadFiles</param>
18             <result name="success">WEB-INF/page/regSucc.jsp</result>
19             <!-- 指定输入校验失败后返回register.jsp界面 -->
20             <result name="input">/WEB-INF/page/register.jsp</result>
21             <interceptor-ref name="fileUpload">
22                 <!-- 配置允许上传的文件类型 -->
23                 <param name="allowedTypes">image/bmp,image/png,image/gif,image/jpeg,image/pjpeg</param>
24                 <!-- 配置允许上传的文件大小  1M -->
25                 <param name="maximumSize">1048576</param>
26             </interceptor-ref>
27             <!-- 配置系统默认拦截器 -->
28             <interceptor-ref name="defaultStack"></interceptor-ref>
29         </action>
30         <action name="releaseBlog" class="releaseBlog">
31             <result name="success"  type="redirectAction">goUserBlogUi</result>
32         </action>
33     </package>
34 
35 </struts>    
View Code

WebRoot

  index.jsp

  1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
  2 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
  3 <%
  4     String path = request.getContextPath();
  5     String basePath = request.getScheme()
  6             + "://"
  7             + request.getServerName()
  8             + ":"
  9             + request.getServerPort()
 10             + path + "/";
 11 %>
 12 
 13 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 14 <html>
 15 <head>
 16 <base href="<%=basePath%>">
 17 
 18 <title>frank_blog_index</title>
 19 <meta http-equiv="pragma" content="no-cache">
 20 <meta http-equiv="cache-control" content="no-cache">
 21 <meta http-equiv="expires" content="0">
 22 <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
 23 <meta http-equiv="description" content="This is my page">
 24 
 25 <style type="text/css">
 26 body {
 27     font: 100%/1.4 Verdana, Arial, Helvetica, sans-serif;
 28     background: #4E5869;
 29     margin: 0;
 30     padding: 0;
 31     color: #000;
 32 }
 33 
 34 /* ~~ 元素/标签选择器 ~~ */
 35 ul,ol,dl {
 36     /* 由于浏览器之间的差异,最佳做法是在列表中将填充和边距都设置为零。为了保持一致,您可以在此处指定需要的数值,也可以在列表所包含的列表项(LI、DT 和 DD)中指定需要的数值。请注意,除非编写一个更为具体的选择器,否则您在此处进行的设置将会层叠到 .nav 列表。 */
 37     padding: 0;
 38     margin: 0;
 39 }
 40 
 41 h1,h2,h3,h4,h5,h6,p {
 42     margin-top: 0;
 43     /* 删除上边距可以解决边距会超出其包含的 div 的问题。剩余的下边距可以使 div 与后面的任何元素保持一定距离。 */
 44     padding-right: 15px;
 45     padding-left: 15px;
 46     /* 向 div 内的元素侧边(而不是 div 自身)添加填充可避免使用任何方框模型数学。此外,也可将具有侧边填充的嵌套 div 用作替代方法。 */
 47 }
 48 
 49 a img { /* 此选择器将删除某些浏览器中显示在图像周围的默认蓝色边框(当该图像包含在链接中时) */
 50     border: none;
 51 }
 52 
 53 /* ~~ 站点链接的样式必须保持此顺序,包括用于创建悬停效果的选择器组在内。 ~~ */
 54 a:link {
 55     color: #414958;
 56     text-decoration: underline;
 57     /* 除非将链接设置成极为独特的外观样式,否则最好提供下划线,以便可从视觉上快速识别 */
 58 }
 59 
 60 a:visited {
 61     color: #4E5869;
 62     text-decoration: underline;
 63 }
 64 
 65 a:hover,a:active,a:focus { /* 此组选择器将为键盘导航者提供与鼠标使用者相同的悬停体验。 */
 66     text-decoration: none;
 67 }
 68 
 69 /* ~~ 此容器包含所有其它 div,并依百分比设定其宽度 ~~ */
 70 .container {
 71     width: 80%;
 72     max-width: 1260px;
 73     /* 可能需要最大宽度,以防止此布局在大型显示器上过宽。这将使行长度更便于阅读。IE6 不遵循此声明。 */
 74     min-width: 780px; /* 可能需要最小宽度,以防止此布局过窄。这将使侧面列中的行长度更便于阅读。IE6 不遵循此声明。 */
 75     background: #FFF;
 76     margin: 0 auto;
 77     /* 侧边的自动值与宽度结合使用,可以将布局居中对齐。如果将 .container 宽度设置为 100%,则不需要此设置。 */
 78 }
 79 
 80 /* ~~ 标题未指定宽度。它将扩展到布局的完整宽度。标题包含一个图像占位符,该占位符应替换为您自己的链接徽标 ~~ */
 81 .header {
 82     background: #6F7D94;
 83 }
 84 
 85 /* ~~ 这是布局信息。 ~~ 
 86 
 87 1) 填充只会放置于 div 的顶部和/或底部。此 div 中的元素侧边会有填充。这样,您可以避免使用任何“方框模型数学”。请注意,如果向 div 自身添加任何侧边填充或边框,这些侧边填充或边框将与您定义的宽度相加,得出 *总计* 宽度。您也可以选择删除 div 中的元素的填充,并在该元素中另外放置一个没有任何宽度但具有设计所需填充的 div。
 88 
 89 */
 90 .content {
 91     padding: 10px 0;
 92 }
 93 
 94 /* ~~ 此分组的选择器为 .content 区域中的列表提供了空间 ~~ */
 95 .content ul,.content ol {
 96     padding: 0 15px 15px 40px;
 97     /* 此填充反映上述标题和段落规则中的右填充。填充放置于下方可用于间隔列表中其它元素,置于左侧可用于创建缩进。您可以根据需要进行调整。 */
 98 }
 99 
100 /* ~~ 脚注 ~~ */
101 .footer {
102     padding: 10px 0;
103     background: #6F7D94;
104 }
105 
106 /* ~~ 其它浮动/清除类 ~~ */
107 .fltrt { /* 此类可用于在页面中使元素向右浮动。浮动元素必须位于其在页面上的相邻元素之前。 */
108     float: right;
109     margin-left: 8px;
110 }
111 
112 .fltlft { /* 此类可用于在页面中使元素向左浮动。浮动元素必须位于其在页面上的相邻元素之前。 */
113     float: left;
114     margin-right: 8px;
115 }
116 
117 .clearfloat {
118     /* 如果从 #container 中删除或移出了 #footer,则可以将此类放置在 <br /> 或空 div 中,作为 #container 内最后一个浮动 div 之后的最终元素 */
119     clear: both;
120     height: 0;
121     font-size: 1px;
122     line-height: 0px;
123 }
124 </style>
125 <!--
126     <link rel="stylesheet" type="text/css" href="styles.css">
127     -->
128 </head>
129 
130 <body>
131 
132     <div class="container">
133         <div class="header">
134             <a href="#"><img src="img/logo.png" alt="唯一的不变是改变"
135                 name="Insert_logo" width="20%" height="90" id="Insert_logo"
136                 style="background: #8090AB; display:block;" /></a>
137             <div>
138                 
139                 <c:if test="${loginUser==null }">
140                     <form action="loginAction" method="post">
141                         用户id:<input type="text" name="userId" /> 密码<input type="password"
142                             name="passwd" /> <input type="submit" value="登录" />
143                     </form>
144 
145                 </c:if>
146                 <a href="goRegisterUi">注册</a>
147                 <c:if test="${loginUser!=null }">
148                 欢迎您${loginUser.userName}<img src="${loginUser.portrait }" width="60px" /><br>
149                  &nbsp;<a href="goUserBlogUi">进入我的博客</a>&nbsp;<a
150                     href="logoutAction">退出登录</a>
151                 </c:if>
152 
153 
154 
155             </div>
156             <!-- end .header -->
157         </div>
158         <div class="content">
159         <h1>最近发布的博文</h1>
160         <c:forEach items="${arts }" var="art">
161             <h2><a href="goShowArtDetUi?id=${art.id }">${art.title }</a></h2><h6>${art.postTime}</h6>
162             <p>${art.contents }</p>
163             <hr />
164         </c:forEach>
165             
166 
167             <h2>&nbsp;</h2>
168             <!-- end .content -->
169         </div>
170         <div class="footer">
171             <p>脚注</p>
172             <!-- end .footer -->
173         </div>
174         <!-- end .container -->
175     </div>
176 </body>
177 </html>
View Code

WEB-INF

  web.xml

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
 3   <display-name>frank_blog</display-name>
 4   <welcome-file-list>
 5     <welcome-file>index.html</welcome-file>
 6     <welcome-file>index.htm</welcome-file>
 7     <welcome-file>index.jsp</welcome-file>
 8     <welcome-file>default.html</welcome-file>
 9     <welcome-file>default.htm</welcome-file>
10     <welcome-file>default.jsp</welcome-file>
11   </welcome-file-list>
12   <listener>
13     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
14   </listener>
15   <context-param>
16     <param-name>contextConfigLocation</param-name>
17     <param-value>classpath:applicationContext.xml</param-value>
18   </context-param>
19   <filter>
20     <filter-name>struts2</filter-name>
21     <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
22   </filter>
23   <filter-mapping>
24     <filter-name>struts2</filter-name>
25     <url-pattern>/*</url-pattern>
26   </filter-mapping>
27 </web-app>
View Code

    page

      newArt.jsp

  1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
  2 <%@ taglib prefix="s" uri="/struts-tags"%>
  3 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
  4 <%
  5     String path = request.getContextPath();
  6     String basePath = request.getScheme()
  7             + "://"
  8             + request.getServerName()
  9             + ":"
 10             + request.getServerPort()
 11             + path + "/";
 12 %>
 13 
 14 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 15 <html>
 16 <head>
 17 <base href="<%=basePath%>">
 18 
 19 <title>frank_blog_index</title>
 20 <meta http-equiv="pragma" content="no-cache">
 21 <meta http-equiv="cache-control" content="no-cache">
 22 <meta http-equiv="expires" content="0">
 23 <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
 24 <meta http-equiv="description" content="This is my page">
 25 
 26 <style type="text/css">
 27 body {
 28     font: 100%/1.4 Verdana, Arial, Helvetica, sans-serif;
 29     background: #4E5869;
 30     margin: 0;
 31     padding: 0;
 32     color: #000;
 33 }
 34 
 35 /* ~~ 元素/标签选择器 ~~ */
 36 ul,ol,dl {
 37     /* 由于浏览器之间的差异,最佳做法是在列表中将填充和边距都设置为零。为了保持一致,您可以在此处指定需要的数值,也可以在列表所包含的列表项(LI、DT 和 DD)中指定需要的数值。请注意,除非编写一个更为具体的选择器,否则您在此处进行的设置将会层叠到 .nav 列表。 */
 38     padding: 0;
 39     margin: 0;
 40 }
 41 
 42 h1,h2,h3,h4,h5,h6,p {
 43     margin-top: 0;
 44     /* 删除上边距可以解决边距会超出其包含的 div 的问题。剩余的下边距可以使 div 与后面的任何元素保持一定距离。 */
 45     padding-right: 15px;
 46     padding-left: 15px;
 47     /* 向 div 内的元素侧边(而不是 div 自身)添加填充可避免使用任何方框模型数学。此外,也可将具有侧边填充的嵌套 div 用作替代方法。 */
 48 }
 49 
 50 a img { /* 此选择器将删除某些浏览器中显示在图像周围的默认蓝色边框(当该图像包含在链接中时) */
 51     border: none;
 52 }
 53 
 54 /* ~~ 站点链接的样式必须保持此顺序,包括用于创建悬停效果的选择器组在内。 ~~ */
 55 a:link {
 56     color: #414958;
 57     text-decoration: underline;
 58     /* 除非将链接设置成极为独特的外观样式,否则最好提供下划线,以便可从视觉上快速识别 */
 59 }
 60 
 61 a:visited {
 62     color: #4E5869;
 63     text-decoration: underline;
 64 }
 65 
 66 a:hover,a:active,a:focus { /* 此组选择器将为键盘导航者提供与鼠标使用者相同的悬停体验。 */
 67     text-decoration: none;
 68 }
 69 
 70 /* ~~ 此容器包含所有其它 div,并依百分比设定其宽度 ~~ */
 71 .container {
 72     width: 80%;
 73     max-width: 1260px;
 74     /* 可能需要最大宽度,以防止此布局在大型显示器上过宽。这将使行长度更便于阅读。IE6 不遵循此声明。 */
 75     min-width: 780px; /* 可能需要最小宽度,以防止此布局过窄。这将使侧面列中的行长度更便于阅读。IE6 不遵循此声明。 */
 76     background: #FFF;
 77     margin: 0 auto;
 78     /* 侧边的自动值与宽度结合使用,可以将布局居中对齐。如果将 .container 宽度设置为 100%,则不需要此设置。 */
 79 }
 80 
 81 /* ~~ 标题未指定宽度。它将扩展到布局的完整宽度。标题包含一个图像占位符,该占位符应替换为您自己的链接徽标 ~~ */
 82 .header {
 83     background: #6F7D94;
 84 }
 85 
 86 /* ~~ 这是布局信息。 ~~ 
 87 
 88 1) 填充只会放置于 div 的顶部和/或底部。此 div 中的元素侧边会有填充。这样,您可以避免使用任何“方框模型数学”。请注意,如果向 div 自身添加任何侧边填充或边框,这些侧边填充或边框将与您定义的宽度相加,得出 *总计* 宽度。您也可以选择删除 div 中的元素的填充,并在该元素中另外放置一个没有任何宽度但具有设计所需填充的 div。
 89 
 90 */
 91 .content {
 92     padding: 10px 0;
 93 }
 94 
 95 /* ~~ 此分组的选择器为 .content 区域中的列表提供了空间 ~~ */
 96 .content ul,.content ol {
 97     padding: 0 15px 15px 40px;
 98     /* 此填充反映上述标题和段落规则中的右填充。填充放置于下方可用于间隔列表中其它元素,置于左侧可用于创建缩进。您可以根据需要进行调整。 */
 99 }
100 
101 /* ~~ 脚注 ~~ */
102 .footer {
103     padding: 10px 0;
104     background: #6F7D94;
105 }
106 
107 /* ~~ 其它浮动/清除类 ~~ */
108 .fltrt { /* 此类可用于在页面中使元素向右浮动。浮动元素必须位于其在页面上的相邻元素之前。 */
109     float: right;
110     margin-left: 8px;
111 }
112 
113 .fltlft { /* 此类可用于在页面中使元素向左浮动。浮动元素必须位于其在页面上的相邻元素之前。 */
114     float: left;
115     margin-right: 8px;
116 }
117 
118 .clearfloat {
119     /* 如果从 #container 中删除或移出了 #footer,则可以将此类放置在 <br /> 或空 div 中,作为 #container 内最后一个浮动 div 之后的最终元素 */
120     clear: both;
121     height: 0;
122     font-size: 1px;
123     line-height: 0px;
124 }
125 </style>
126 <!--
127     <link rel="stylesheet" type="text/css" href="styles.css">
128     -->
129 </head>
130 
131 <body>
132 
133     <div class="container">
134         <div class="header">
135             <a href="#"><img src="img/logo.png" alt="唯一的不变是改变"
136                 name="Insert_logo" width="20%" height="90" id="Insert_logo"
137                 style="background: #8090AB; display:block;" /></a>
138             <div></div>
139             <!-- end .header -->
140         </div>
141         <div class="content">
142             <s:form action="releaseBlog"  method="post">
143                 <table>
144                     <tr>
145                         <td><s:textfield name="title" label="标题" ></s:textfield>
146                     </tr>
147                     <tr>
148                         <td>类型</td>
149                         <td><select name="type">
150                                 <option value="O">原创</option>
151                                 <option value="R">转载</option>
152                                 <option value="T">翻译</option>
153                         </select></td>
154 
155                     </tr>
156                     <tr>
157                         <s:textarea rows="10" cols="25" name="contents" ></s:textarea>
158                         
159                     </tr>
160                     <tr>
161                         <td><s:submit value="发布" /></td>
162                     </tr>
163                 </table>
164 
165             </s:form>
166 
167 
168             <h2>&nbsp;</h2>
169             <!-- end .content -->
170         </div>
171         <div class="footer">
172             <p>脚注</p>
173             <!-- end .footer -->
174         </div>
175         <!-- end .container -->
176     </div>
177 </body>
178 </html>
View Code

      register.jsp

  1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
  2 <%@ taglib prefix="s"  uri="/struts-tags"%>
  3 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
  4 <%
  5     String path = request.getContextPath();
  6     String basePath = request.getScheme()
  7             + "://"
  8             + request.getServerName()
  9             + ":"
 10             + request.getServerPort()
 11             + path + "/";
 12 %>
 13 
 14 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 15 <html>
 16 <head>
 17 <base href="<%=basePath%>">
 18 
 19 <title>frank_blog_index</title>
 20 <meta http-equiv="pragma" content="no-cache">
 21 <meta http-equiv="cache-control" content="no-cache">
 22 <meta http-equiv="expires" content="0">
 23 <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
 24 <meta http-equiv="description" content="This is my page">
 25 
 26 <style type="text/css">
 27 body {
 28     font: 100%/1.4 Verdana, Arial, Helvetica, sans-serif;
 29     background: #4E5869;
 30     margin: 0;
 31     padding: 0;
 32     color: #000;
 33 }
 34 
 35 /* ~~ 元素/标签选择器 ~~ */
 36 ul,ol,dl {
 37     /* 由于浏览器之间的差异,最佳做法是在列表中将填充和边距都设置为零。为了保持一致,您可以在此处指定需要的数值,也可以在列表所包含的列表项(LI、DT 和 DD)中指定需要的数值。请注意,除非编写一个更为具体的选择器,否则您在此处进行的设置将会层叠到 .nav 列表。 */
 38     padding: 0;
 39     margin: 0;
 40 }
 41 
 42 h1,h2,h3,h4,h5,h6,p {
 43     margin-top: 0;
 44     /* 删除上边距可以解决边距会超出其包含的 div 的问题。剩余的下边距可以使 div 与后面的任何元素保持一定距离。 */
 45     padding-right: 15px;
 46     padding-left: 15px;
 47     /* 向 div 内的元素侧边(而不是 div 自身)添加填充可避免使用任何方框模型数学。此外,也可将具有侧边填充的嵌套 div 用作替代方法。 */
 48 }
 49 
 50 a img { /* 此选择器将删除某些浏览器中显示在图像周围的默认蓝色边框(当该图像包含在链接中时) */
 51     border: none;
 52 }
 53 
 54 /* ~~ 站点链接的样式必须保持此顺序,包括用于创建悬停效果的选择器组在内。 ~~ */
 55 a:link {
 56     color: #414958;
 57     text-decoration: underline;
 58     /* 除非将链接设置成极为独特的外观样式,否则最好提供下划线,以便可从视觉上快速识别 */
 59 }
 60 
 61 a:visited {
 62     color: #4E5869;
 63     text-decoration: underline;
 64 }
 65 
 66 a:hover,a:active,a:focus { /* 此组选择器将为键盘导航者提供与鼠标使用者相同的悬停体验。 */
 67     text-decoration: none;
 68 }
 69 
 70 /* ~~ 此容器包含所有其它 div,并依百分比设定其宽度 ~~ */
 71 .container {
 72     width: 80%;
 73     max-width: 1260px;
 74     /* 可能需要最大宽度,以防止此布局在大型显示器上过宽。这将使行长度更便于阅读。IE6 不遵循此声明。 */
 75     min-width: 780px; /* 可能需要最小宽度,以防止此布局过窄。这将使侧面列中的行长度更便于阅读。IE6 不遵循此声明。 */
 76     background: #FFF;
 77     margin: 0 auto;
 78     /* 侧边的自动值与宽度结合使用,可以将布局居中对齐。如果将 .container 宽度设置为 100%,则不需要此设置。 */
 79 }
 80 
 81 /* ~~ 标题未指定宽度。它将扩展到布局的完整宽度。标题包含一个图像占位符,该占位符应替换为您自己的链接徽标 ~~ */
 82 .header {
 83     background: #6F7D94;
 84 }
 85 
 86 /* ~~ 这是布局信息。 ~~ 
 87 
 88 1) 填充只会放置于 div 的顶部和/或底部。此 div 中的元素侧边会有填充。这样,您可以避免使用任何“方框模型数学”。请注意,如果向 div 自身添加任何侧边填充或边框,这些侧边填充或边框将与您定义的宽度相加,得出 *总计* 宽度。您也可以选择删除 div 中的元素的填充,并在该元素中另外放置一个没有任何宽度但具有设计所需填充的 div。
 89 
 90 */
 91 .content {
 92     padding: 10px 0;
 93 }
 94 
 95 /* ~~ 此分组的选择器为 .content 区域中的列表提供了空间 ~~ */
 96 .content ul,.content ol {
 97     padding: 0 15px 15px 40px;
 98     /* 此填充反映上述标题和段落规则中的右填充。填充放置于下方可用于间隔列表中其它元素,置于左侧可用于创建缩进。您可以根据需要进行调整。 */
 99 }
100 
101 /* ~~ 脚注 ~~ */
102 .footer {
103     padding: 10px 0;
104     background: #6F7D94;
105 }
106 
107 /* ~~ 其它浮动/清除类 ~~ */
108 .fltrt { /* 此类可用于在页面中使元素向右浮动。浮动元素必须位于其在页面上的相邻元素之前。 */
109     float: right;
110     margin-left: 8px;
111 }
112 
113 .fltlft { /* 此类可用于在页面中使元素向左浮动。浮动元素必须位于其在页面上的相邻元素之前。 */
114     float: left;
115     margin-right: 8px;
116 }
117 
118 .clearfloat {
119     /* 如果从 #container 中删除或移出了 #footer,则可以将此类放置在 <br /> 或空 div 中,作为 #container 内最后一个浮动 div 之后的最终元素 */
120     clear: both;
121     height: 0;
122     font-size: 1px;
123     line-height: 0px;
124 }
125 </style>
126 <!--
127     <link rel="stylesheet" type="text/css" href="styles.css">
128     -->
129 </head>
130 
131 <body>
132 
133     <div class="container">
134         <div class="header">
135             <a href="#"><img src="img/logo.png" alt="唯一的不变是改变"
136                 name="Insert_logo" width="20%" height="90" id="Insert_logo"
137                 style="background: #8090AB; display:block;" /></a>
138             <div>
139                 
140 
141             </div>
142             <!-- end .header -->
143         </div>
144         <div class="content">
145         <s:form action="doRegist" enctype="multipart/form-data" validate="true" method="post">
146         <table>
147             <tr>
148                 <td><s:textfield  name="userName"  label="用户名"></s:textfield>
149             </tr>
150             <tr>
151                 <td><s:password name="passwd" label="密码"></s:password>
152                 
153             </tr>
154             <tr>
155                 <td>性别</td>
156                 <td><select name="sex"><option value="F"></option><option value="M"></select></td>
157             </tr>
158             <tr>
159                 <td>
160                 <s:file name="portrait" label="头像"></s:file>
161                 </td>
162             </tr>
163             <tr>
164                 <td>
165                     <s:submit value="注册"/>
166                 </td>
167             </tr>
168         </table>
169 
170     </s:form>
171             
172 
173             <h2>&nbsp;</h2>
174             <!-- end .content -->
175         </div>
176         <div class="footer">
177             <p>脚注</p>
178             <!-- end .footer -->
179         </div>
180         <!-- end .container -->
181     </div>
182 </body>
183 </html>
View Code

      regSucc.jsp

  1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
  2 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
  3 <%
  4     String path = request.getContextPath();
  5     String basePath = request.getScheme()
  6             + "://"
  7             + request.getServerName()
  8             + ":"
  9             + request.getServerPort()
 10             + path + "/";
 11 %>
 12 
 13 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 14 <html>
 15 <head>
 16 <base href="<%=basePath%>">
 17 
 18 <title>frank_blog_index</title>
 19 <meta http-equiv="pragma" content="no-cache">
 20 <meta http-equiv="cache-control" content="no-cache">
 21 <meta http-equiv="expires" content="0">
 22 <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
 23 <meta http-equiv="description" content="This is my page">
 24 
 25 <style type="text/css">
 26 body {
 27     font: 100%/1.4 Verdana, Arial, Helvetica, sans-serif;
 28     background: #4E5869;
 29     margin: 0;
 30     padding: 0;
 31     color: #000;
 32 }
 33 
 34 /* ~~ 元素/标签选择器 ~~ */
 35 ul,ol,dl {
 36     /* 由于浏览器之间的差异,最佳做法是在列表中将填充和边距都设置为零。为了保持一致,您可以在此处指定需要的数值,也可以在列表所包含的列表项(LI、DT 和 DD)中指定需要的数值。请注意,除非编写一个更为具体的选择器,否则您在此处进行的设置将会层叠到 .nav 列表。 */
 37     padding: 0;
 38     margin: 0;
 39 }
 40 
 41 h1,h2,h3,h4,h5,h6,p {
 42     margin-top: 0;
 43     /* 删除上边距可以解决边距会超出其包含的 div 的问题。剩余的下边距可以使 div 与后面的任何元素保持一定距离。 */
 44     padding-right: 15px;
 45     padding-left: 15px;
 46     /* 向 div 内的元素侧边(而不是 div 自身)添加填充可避免使用任何方框模型数学。此外,也可将具有侧边填充的嵌套 div 用作替代方法。 */
 47 }
 48 
 49 a img { /* 此选择器将删除某些浏览器中显示在图像周围的默认蓝色边框(当该图像包含在链接中时) */
 50     border: none;
 51 }
 52 
 53 /* ~~ 站点链接的样式必须保持此顺序,包括用于创建悬停效果的选择器组在内。 ~~ */
 54 a:link {
 55     color: #414958;
 56     text-decoration: underline;
 57     /* 除非将链接设置成极为独特的外观样式,否则最好提供下划线,以便可从视觉上快速识别 */
 58 }
 59 
 60 a:visited {
 61     color: #4E5869;
 62     text-decoration: underline;
 63 }
 64 
 65 a:hover,a:active,a:focus { /* 此组选择器将为键盘导航者提供与鼠标使用者相同的悬停体验。 */
 66     text-decoration: none;
 67 }
 68 
 69 /* ~~ 此容器包含所有其它 div,并依百分比设定其宽度 ~~ */
 70 .container {
 71     width: 80%;
 72     max-width: 1260px;
 73     /* 可能需要最大宽度,以防止此布局在大型显示器上过宽。这将使行长度更便于阅读。IE6 不遵循此声明。 */
 74     min-width: 780px; /* 可能需要最小宽度,以防止此布局过窄。这将使侧面列中的行长度更便于阅读。IE6 不遵循此声明。 */
 75     background: #FFF;
 76     margin: 0 auto;
 77     /* 侧边的自动值与宽度结合使用,可以将布局居中对齐。如果将 .container 宽度设置为 100%,则不需要此设置。 */
 78 }
 79 
 80 /* ~~ 标题未指定宽度。它将扩展到布局的完整宽度。标题包含一个图像占位符,该占位符应替换为您自己的链接徽标 ~~ */
 81 .header {
 82     background: #6F7D94;
 83 }
 84 
 85 /* ~~ 这是布局信息。 ~~ 
 86 
 87 1) 填充只会放置于 div 的顶部和/或底部。此 div 中的元素侧边会有填充。这样,您可以避免使用任何“方框模型数学”。请注意,如果向 div 自身添加任何侧边填充或边框,这些侧边填充或边框将与您定义的宽度相加,得出 *总计* 宽度。您也可以选择删除 div 中的元素的填充,并在该元素中另外放置一个没有任何宽度但具有设计所需填充的 div。
 88 
 89 */
 90 .content {
 91     padding: 10px 0;
 92 }
 93 
 94 /* ~~ 此分组的选择器为 .content 区域中的列表提供了空间 ~~ */
 95 .content ul,.content ol {
 96     padding: 0 15px 15px 40px;
 97     /* 此填充反映上述标题和段落规则中的右填充。填充放置于下方可用于间隔列表中其它元素,置于左侧可用于创建缩进。您可以根据需要进行调整。 */
 98 }
 99 
100 /* ~~ 脚注 ~~ */
101 .footer {
102     padding: 10px 0;
103     background: #6F7D94;
104 }
105 
106 /* ~~ 其它浮动/清除类 ~~ */
107 .fltrt { /* 此类可用于在页面中使元素向右浮动。浮动元素必须位于其在页面上的相邻元素之前。 */
108     float: right;
109     margin-left: 8px;
110 }
111 
112 .fltlft { /* 此类可用于在页面中使元素向左浮动。浮动元素必须位于其在页面上的相邻元素之前。 */
113     float: left;
114     margin-right: 8px;
115 }
116 
117 .clearfloat {
118     /* 如果从 #container 中删除或移出了 #footer,则可以将此类放置在 <br /> 或空 div 中,作为 #container 内最后一个浮动 div 之后的最终元素 */
119     clear: both;
120     height: 0;
121     font-size: 1px;
122     line-height: 0px;
123 }
124 </style>
125 <!--
126     <link rel="stylesheet" type="text/css" href="styles.css">
127     -->
128 </head>
129 
130 <body>
131 
132     <div class="container">
133         <div class="header">
134             <a href="#"><img src="img/logo.png" alt="唯一的不变是改变"
135                 name="Insert_logo" width="20%" height="90" id="Insert_logo"
136                 style="background: #8090AB; display:block;" /></a>
137             <div>
138                 恭喜,注册成功 ${loginUser.userName },您的id号为${loginUser.id }<br/>
139                 <img src="${loginUser.portrait }" width="60px" /><br>
140                 欢迎您${loginUser.userName} <a href="goRegisterUi">注册</a>&nbsp;<a href="goUserBlogUi">进入我的博客</a>&nbsp;<a
141                     href="logoutAction">退出登录</a>
142 
143             </div>
144             <!-- end .header -->
145         </div>
146         <div class="content">
147         <h1>最近发布的博文</h1>
148         <c:forEach items="${arts }" var="art">
149             <h2><a href="#">${art.title }</a></h2><h6>${art.postTime}</h6>
150             <p>${art.contents }</p>
151             <hr />
152         </c:forEach>
153             
154 
155             <h2>&nbsp;</h2>
156             <!-- end .content -->
157         </div>
158         <div class="footer">
159             <p>脚注</p>
160             <!-- end .footer -->
161         </div>
162         <!-- end .container -->
163     </div>
164 </body>
165 </html>
166 
167     
168     
View Code

      showArtDet.jsp

  1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
  2 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
  3 <%
  4     String path = request.getContextPath();
  5     String basePath = request.getScheme()
  6             + "://"
  7             + request.getServerName()
  8             + ":"
  9             + request.getServerPort()
 10             + path + "/";
 11 %>
 12 
 13 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 14 <html>
 15 <head>
 16 <base href="<%=basePath%>">
 17 
 18 <title>frank_blog_index</title>
 19 <meta http-equiv="pragma" content="no-cache">
 20 <meta http-equiv="cache-control" content="no-cache">
 21 <meta http-equiv="expires" content="0">
 22 <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
 23 <meta http-equiv="description" content="This is my page">
 24 
 25 <style type="text/css">
 26 body {
 27     font: 100%/1.4 Verdana, Arial, Helvetica, sans-serif;
 28     background: #4E5869;
 29     margin: 0;
 30     padding: 0;
 31     color: #000;
 32 }
 33 
 34 /* ~~ 元素/标签选择器 ~~ */
 35 ul,ol,dl {
 36     /* 由于浏览器之间的差异,最佳做法是在列表中将填充和边距都设置为零。为了保持一致,您可以在此处指定需要的数值,也可以在列表所包含的列表项(LI、DT 和 DD)中指定需要的数值。请注意,除非编写一个更为具体的选择器,否则您在此处进行的设置将会层叠到 .nav 列表。 */
 37     padding: 0;
 38     margin: 0;
 39 }
 40 
 41 h1,h2,h3,h4,h5,h6,p {
 42     margin-top: 0;
 43     /* 删除上边距可以解决边距会超出其包含的 div 的问题。剩余的下边距可以使 div 与后面的任何元素保持一定距离。 */
 44     padding-right: 15px;
 45     padding-left: 15px;
 46     /* 向 div 内的元素侧边(而不是 div 自身)添加填充可避免使用任何方框模型数学。此外,也可将具有侧边填充的嵌套 div 用作替代方法。 */
 47 }
 48 
 49 a img { /* 此选择器将删除某些浏览器中显示在图像周围的默认蓝色边框(当该图像包含在链接中时) */
 50     border: none;
 51 }
 52 
 53 /* ~~ 站点链接的样式必须保持此顺序,包括用于创建悬停效果的选择器组在内。 ~~ */
 54 a:link {
 55     color: #414958;
 56     text-decoration: underline;
 57     /* 除非将链接设置成极为独特的外观样式,否则最好提供下划线,以便可从视觉上快速识别 */
 58 }
 59 
 60 a:visited {
 61     color: #4E5869;
 62     text-decoration: underline;
 63 }
 64 
 65 a:hover,a:active,a:focus { /* 此组选择器将为键盘导航者提供与鼠标使用者相同的悬停体验。 */
 66     text-decoration: none;
 67 }
 68 
 69 /* ~~ 此容器包含所有其它 div,并依百分比设定其宽度 ~~ */
 70 .container {
 71     width: 80%;
 72     max-width: 1260px;
 73     /* 可能需要最大宽度,以防止此布局在大型显示器上过宽。这将使行长度更便于阅读。IE6 不遵循此声明。 */
 74     min-width: 780px; /* 可能需要最小宽度,以防止此布局过窄。这将使侧面列中的行长度更便于阅读。IE6 不遵循此声明。 */
 75     background: #FFF;
 76     margin: 0 auto;
 77     /* 侧边的自动值与宽度结合使用,可以将布局居中对齐。如果将 .container 宽度设置为 100%,则不需要此设置。 */
 78 }
 79 
 80 /* ~~ 标题未指定宽度。它将扩展到布局的完整宽度。标题包含一个图像占位符,该占位符应替换为您自己的链接徽标 ~~ */
 81 .header {
 82     background: #6F7D94;
 83 }
 84 
 85 /* ~~ 这是布局信息。 ~~ 
 86 
 87 1) 填充只会放置于 div 的顶部和/或底部。此 div 中的元素侧边会有填充。这样,您可以避免使用任何“方框模型数学”。请注意,如果向 div 自身添加任何侧边填充或边框,这些侧边填充或边框将与您定义的宽度相加,得出 *总计* 宽度。您也可以选择删除 div 中的元素的填充,并在该元素中另外放置一个没有任何宽度但具有设计所需填充的 div。
 88 
 89 */
 90 .content {
 91     padding: 10px 0;
 92 }
 93 
 94 /* ~~ 此分组的选择器为 .content 区域中的列表提供了空间 ~~ */
 95 .content ul,.content ol {
 96     padding: 0 15px 15px 40px;
 97     /* 此填充反映上述标题和段落规则中的右填充。填充放置于下方可用于间隔列表中其它元素,置于左侧可用于创建缩进。您可以根据需要进行调整。 */
 98 }
 99 
100 /* ~~ 脚注 ~~ */
101 .footer {
102     padding: 10px 0;
103     background: #6F7D94;
104 }
105 
106 /* ~~ 其它浮动/清除类 ~~ */
107 .fltrt { /* 此类可用于在页面中使元素向右浮动。浮动元素必须位于其在页面上的相邻元素之前。 */
108     float: right;
109     margin-left: 8px;
110 }
111 
112 .fltlft { /* 此类可用于在页面中使元素向左浮动。浮动元素必须位于其在页面上的相邻元素之前。 */
113     float: left;
114     margin-right: 8px;
115 }
116 
117 .clearfloat {
118     /* 如果从 #container 中删除或移出了 #footer,则可以将此类放置在 <br /> 或空 div 中,作为 #container 内最后一个浮动 div 之后的最终元素 */
119     clear: both;
120     height: 0;
121     font-size: 1px;
122     line-height: 0px;
123 }
124 </style>
125 <!--
126     <link rel="stylesheet" type="text/css" href="styles.css">
127     -->
128 </head>
129 
130 <body>
131 
132     <div class="container">
133         <div class="header">
134             <a href="#"><img src="img/logo.png" alt="唯一的不变是改变"
135                 name="Insert_logo" width="20%" height="90" id="Insert_logo"
136                 style="background: #8090AB; display:block;" /></a>
137             <div>
138                 
139                 <c:if test="${loginUser==null }">
140                     <form action="loginAction" method="post">
141                         用户id:<input type="text" name="userId" /> 密码<input type="password"
142                             name="passwd" /> <input type="submit" value="登录" />
143                     </form>
144 
145                 </c:if>
146                 <a href="goRegisterUi">注册</a>
147                 <c:if test="${loginUser!=null }">
148                 欢迎您${loginUser.userName}<img src="${loginUser.portrait }" width="60px" /><br>
149                  &nbsp;<a href="goUserBlogUi">进入我的博客</a>&nbsp;<a
150                     href="logoutAction">退出登录</a>
151                 </c:if>
152 
153 
154 
155             </div>
156             <!-- end .header -->
157         </div>
158         <div class="content">
159         <h1>${art.title }</h1><hr>
160         
161         <h6>${art.postTime}</h6>
162             <p>${art.contents }</p>
163         
164             
165 
166             <h2>&nbsp;</h2>
167             <!-- end .content -->
168         </div>
169         <div class="footer">
170             <p>脚注</p>
171             <!-- end .footer -->
172         </div>
173         <!-- end .container -->
174     </div>
175 </body>
176 </html>
View Code

      userBlog.jsp

  1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
  2 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
  3 <%
  4     String path = request.getContextPath();
  5     String basePath = request.getScheme()
  6             + "://"
  7             + request.getServerName()
  8             + ":"
  9             + request.getServerPort()
 10             + path + "/";
 11 %>
 12 
 13 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 14 <html>
 15 <head>
 16 <base href="<%=basePath%>">
 17 
 18 <title>frank_blog_index</title>
 19 <meta http-equiv="pragma" content="no-cache">
 20 <meta http-equiv="cache-control" content="no-cache">
 21 <meta http-equiv="expires" content="0">
 22 <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
 23 <meta http-equiv="description" content="This is my page">
 24 
 25 <style type="text/css">
 26 body {
 27     font: 100%/1.4 Verdana, Arial, Helvetica, sans-serif;
 28     background: #4E5869;
 29     margin: 0;
 30     padding: 0;
 31     color: #000;
 32 }
 33 
 34 /* ~~ 元素/标签选择器 ~~ */
 35 ul,ol,dl {
 36     /* 由于浏览器之间的差异,最佳做法是在列表中将填充和边距都设置为零。为了保持一致,您可以在此处指定需要的数值,也可以在列表所包含的列表项(LI、DT 和 DD)中指定需要的数值。请注意,除非编写一个更为具体的选择器,否则您在此处进行的设置将会层叠到 .nav 列表。 */
 37     padding: 0;
 38     margin: 0;
 39 }
 40 
 41 h1,h2,h3,h4,h5,h6,p {
 42     margin-top: 0;
 43     /* 删除上边距可以解决边距会超出其包含的 div 的问题。剩余的下边距可以使 div 与后面的任何元素保持一定距离。 */
 44     padding-right: 15px;
 45     padding-left: 15px;
 46     /* 向 div 内的元素侧边(而不是 div 自身)添加填充可避免使用任何方框模型数学。此外,也可将具有侧边填充的嵌套 div 用作替代方法。 */
 47 }
 48 
 49 a img { /* 此选择器将删除某些浏览器中显示在图像周围的默认蓝色边框(当该图像包含在链接中时) */
 50     border: none;
 51 }
 52 
 53 /* ~~ 站点链接的样式必须保持此顺序,包括用于创建悬停效果的选择器组在内。 ~~ */
 54 a:link {
 55     color: #414958;
 56     text-decoration: underline;
 57     /* 除非将链接设置成极为独特的外观样式,否则最好提供下划线,以便可从视觉上快速识别 */
 58 }
 59 
 60 a:visited {
 61     color: #4E5869;
 62     text-decoration: underline;
 63 }
 64 
 65 a:hover,a:active,a:focus { /* 此组选择器将为键盘导航者提供与鼠标使用者相同的悬停体验。 */
 66     text-decoration: none;
 67 }
 68 
 69 /* ~~ 此容器包含所有其它 div,并依百分比设定其宽度 ~~ */
 70 .container {
 71     width: 80%;
 72     max-width: 1260px;
 73     /* 可能需要最大宽度,以防止此布局在大型显示器上过宽。这将使行长度更便于阅读。IE6 不遵循此声明。 */
 74     min-width: 780px; /* 可能需要最小宽度,以防止此布局过窄。这将使侧面列中的行长度更便于阅读。IE6 不遵循此声明。 */
 75     background: #FFF;
 76     margin: 0 auto;
 77     /* 侧边的自动值与宽度结合使用,可以将布局居中对齐。如果将 .container 宽度设置为 100%,则不需要此设置。 */
 78 }
 79 
 80 /* ~~ 标题未指定宽度。它将扩展到布局的完整宽度。标题包含一个图像占位符,该占位符应替换为您自己的链接徽标 ~~ */
 81 .header {
 82     background: #6F7D94;
 83 }
 84 
 85 /* ~~ 这是布局信息。 ~~ 
 86 
 87 1) 填充只会放置于 div 的顶部和/或底部。此 div 中的元素侧边会有填充。这样,您可以避免使用任何“方框模型数学”。请注意,如果向 div 自身添加任何侧边填充或边框,这些侧边填充或边框将与您定义的宽度相加,得出 *总计* 宽度。您也可以选择删除 div 中的元素的填充,并在该元素中另外放置一个没有任何宽度但具有设计所需填充的 div。
 88 
 89 */
 90 .content {
 91     padding: 10px 0;
 92 }
 93 
 94 /* ~~ 此分组的选择器为 .content 区域中的列表提供了空间 ~~ */
 95 .content ul,.content ol {
 96     padding: 0 15px 15px 40px;
 97     /* 此填充反映上述标题和段落规则中的右填充。填充放置于下方可用于间隔列表中其它元素,置于左侧可用于创建缩进。您可以根据需要进行调整。 */
 98 }
 99 
100 /* ~~ 脚注 ~~ */
101 .footer {
102     padding: 10px 0;
103     background: #6F7D94;
104 }
105 
106 /* ~~ 其它浮动/清除类 ~~ */
107 .fltrt { /* 此类可用于在页面中使元素向右浮动。浮动元素必须位于其在页面上的相邻元素之前。 */
108     float: right;
109     margin-left: 8px;
110 }
111 
112 .fltlft { /* 此类可用于在页面中使元素向左浮动。浮动元素必须位于其在页面上的相邻元素之前。 */
113     float: left;
114     margin-right: 8px;
115 }
116 
117 .clearfloat {
118     /* 如果从 #container 中删除或移出了 #footer,则可以将此类放置在 <br /> 或空 div 中,作为 #container 内最后一个浮动 div 之后的最终元素 */
119     clear: both;
120     height: 0;
121     font-size: 1px;
122     line-height: 0px;
123 }
124 </style>
125 <!--
126     <link rel="stylesheet" type="text/css" href="styles.css">
127     -->
128 </head>
129 
130 <body>
131 
132     <div class="container">
133         <div class="header">
134             <a href="#"><img src="img/logo.png" alt="唯一的不变是改变"
135                 name="Insert_logo" width="20%" height="90" id="Insert_logo"
136                 style="background: #8090AB; display:block;" /></a>
137             <div>
138 
139                 <c:if test="${loginUser==null }">
140                     <form action="loginAction" method="post">
141                         用户id:<input type="text" name="userId" /> 密码<input type="password"
142                             name="passwd" /> <input type="submit" value="登录" />
143                     </form>
144 
145                 </c:if>
146                 欢迎您${loginUser.userName}<img src="${loginUser.portrait }" width="60px" /><br> <a href="#">管理博客</a>&nbsp;
147                 <a href="goNewArtUi">新博文</a>
148                 <a href="logoutAction">退出登录</a>
149 
150             </div>
151             <!-- end .header -->
152         </div>
153         <div class="content">
154         <c:forEach items="${arts }" var="art">
155             <h2><a href="goShowArtDetUi?id=${art.id }">${art.title }</a></h2><h6>${art.postTime}</h6>
156             <p>${art.contents }</p>
157             <hr />
158         </c:forEach>
159             
160 
161             <h2>&nbsp;</h2>
162             <!-- end .content -->
163         </div>
164         <div class="footer">
165             <p>脚注</p>
166             <!-- end .footer -->
167         </div>
168         <!-- end .container -->
169     </div>
170 </body>
171 </html>
View Code
原文地址:https://www.cnblogs.com/frankM/p/4551491.html