淳真淼淼

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

一、这周完成的功能:

1.前台功能模块:

  a.用户注册

  b.会员信息修改

  c.留言板

  d.信息浏览

2.后台功能模块

  a.用户管理

  b.留言中心管理

  c.管理员信息修改

  d.信息发布

二、核心源码:

  applictionContext.xml

 1 <!-- 开启注解 -->
 2     <context:annotation-config/>
 3     <mvc:annotation-driven/>
 4     <!-- 扫描配置 -->
 5     <context:component-scan base-package="com.hp"></context:component-scan>
 6     <!-- 数据源 -->
 7     <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> 
 8         <property name="username" value="root"></property>
 9         <property name="password" value="123456"></property>
10         <property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
11         <property name="url" value="jdbc:mysql://localhost:3306/car?useUnicode=true&amp;characterEncoding=utf-8"></property>
12     </bean>
13     <!-- spring和Mybatis融合 -->
14     <bean id="sqlSession" class="org.mybatis.spring.SqlSessionFactoryBean">
15         <property name="dataSource" ref="dataSource"></property>
16         <property name="mapperLocations" value="classpath:com/hp/dao/*.xml"></property>
17     </bean>
18     <!-- spring自动查找dao下面的类 -->
19     <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
20              <property name="basePackage" value="com.hp.dao"></property>
21              <property name="sqlSessionFactory" ref="sqlSession"></property>
22     </bean> 
23     
24     <!--配置静态资源的访问映射,此配置中的文件,将不被前端控制器拦截 -->
25     <!-- <mvc:resources location="/js/" mapping="/js/**"/> -->
26     <mvc:default-servlet-handler />
27     
28     <!-- 配置文件中添加文件上传解析器 -->
29     <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">    
30      <!-- <property name="defaultEncoding" value="utf-8"></property>    
31      <property name="maxUploadSize" value="10485760000"></property>  -->   <!--设置最大支持的上传文件大小 B-->
32     </bean>
33     </beans>

web.xml

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <web-app version="3.0" 
 3     xmlns="http://java.sun.com/xml/ns/javaee" 
 4     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 5     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
 6     http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
 7   <display-name></display-name>    
 8   <welcome-file-list>
 9     <welcome-file>qloginsuccess.jsp</welcome-file>
10   </welcome-file-list>
11     <servlet>
12         <servlet-name>DispatcherServlet</servlet-name>
13         <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
14         <init-param>
15             <param-name>contextConfigLocation</param-name>
16             <param-value>classpath:applicationContext.xml</param-value>
17         </init-param>
18     </servlet>
19     <servlet-mapping>
20         <servlet-name>DispatcherServlet</servlet-name>
21         <url-pattern>/</url-pattern>
22     </servlet-mapping>
23     <filter>
24         <filter-name>CharacterEncodingFilter</filter-name>
25         <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
26         <init-param>
27             <param-name>encoding</param-name>
28             <param-value>utf-8</param-value>
29         </init-param>
30     </filter>
31     <filter-mapping>
32         <filter-name>CharacterEncodingFilter</filter-name>
33         <url-pattern>/*</url-pattern>
34     </filter-mapping>
35 </web-app>

实体类:com.hp.model

 1 package com.hp.model;
 2 
 3 public class Userinfo {
 4     private Integer userId;
 5     private String uname;
 6     private String upass;
 7     private String urealname;
 8     private String tel;
 9     private String cardId;
10     private String type;
11     private String deleteStatus;
12     
13     public String getDeleteStatus() {
14         return deleteStatus;
15     }
16     public void setDeleteStatus(String deleteStatus) {
17         this.deleteStatus = deleteStatus;
18     }
19     public Integer getUserId() {
20         return userId;
21     }
22     public void setUserId(Integer userId) {
23         this.userId = userId;
24     }
25     public String getUname() {
26         return uname;
27     }
28     public void setUname(String uname) {
29         this.uname = uname;
30     }
31     public String getUpass() {
32         return upass;
33     }
34     public void setUpass(String upass) {
35         this.upass = upass;
36     }
37     public String getUrealname() {
38         return urealname;
39     }
40     public void setUrealname(String urealname) {
41         this.urealname = urealname;
42     }
43     public String getTel() {
44         return tel;
45     }
46     public void setTel(String tel) {
47         this.tel = tel;
48     }
49     public String getCardId() {
50         return cardId;
51     }
52     public void setCardId(String cardId) {
53         this.cardId = cardId;
54     }
55     public String getType() {
56         return type;
57     }
58     public void setType(String type) {
59         this.type = type;
60     }    
61 
62 }
 1 package com.hp.model;
 2 
 3 public class News {
 4     private Integer nid;
 5     private String title;
 6     private String content;
 7     private String savetime;
 8     private String type;
 9     private String imgurl;
10     private String delstatus;
11     
12     public Integer getNid() {
13         return nid;
14     }
15     public void setNid(Integer nid) {
16         this.nid = nid;
17     }
18     public String getTitle() {
19         return title;
20     }
21     public void setTitle(String title) {
22         this.title = title;
23     }
24     public String getContent() {
25         return content;
26     }
27     public void setContent(String content) {
28         this.content = content;
29     }
30     public String getSavetime() {
31         return savetime;
32     }
33     public void setSavetime(String savetime) {
34         this.savetime = savetime;
35     }
36     public String getType() {
37         return type;
38     }
39     public void setType(String type) {
40         this.type = type;
41     }
42     public String getImgurl() {
43         return imgurl;
44     }
45     public void setImgurl(String imgurl) {
46         this.imgurl = imgurl;
47     }
48     public String getDelstatus() {
49         return delstatus;
50     }
51     public void setDelstatus(String delstatus) {
52         this.delstatus = delstatus;
53     }
54     
55     
56 
57 }
 1 package com.hp.model;
 2 
 3 public class Message {
 4     private Integer mid;
 5     private String content;
 6     private String reply;
 7     private String saveTime;
 8     private Userinfo userinfo;
 9     
10     public Integer getMid() {
11         return mid;
12     }
13     public void setMid(Integer mid) {
14         this.mid = mid;
15     }
16     public String getContent() {
17         return content;
18     }
19     public void setContent(String content) {
20         this.content = content;
21     }
22     
23     public String getReply() {
24         return reply;
25     }
26     public void setReply(String reply) {
27         this.reply = reply;
28     }
29     public String getSaveTime() {
30         return saveTime;
31     }
32     public void setSaveTime(String saveTime) {
33         this.saveTime = saveTime;
34     }
35     public Userinfo getUserinfo() {
36         return userinfo;
37     }
38     public void setUserinfo(Userinfo userinfo) {
39         this.userinfo = userinfo;
40     }
41         
42 }

Dao接口:

 1 package com.hp.dao;
 2 
 3 import java.util.List;
 4 
 5 import org.apache.ibatis.annotations.Param;
 6 
 7 import com.hp.model.Userinfo;
 8 
 9 public interface UserinfoDao {
10     
11     //注册
12     Integer add(Userinfo userinfo);
13     //登录
14     Userinfo  login (@Param("uname") String uname,@Param("upass") String upass,@Param("type") String type);
15     //查询所有用户
16     List<Userinfo> findAll();
17     //删除
18     Integer delete(Integer userId);
19     //修改
20     Integer update(Userinfo userinfo);
21     //根据name查找
22     Userinfo find(String uname);
23 
24 }
package com.hp.dao;

import java.util.List;

import com.hp.model.News;

public interface NewsDao {
    
    //查询所有信息
    List<News> findAllNews(String type);
    //添加信息
    Integer addNews(News news);

}
package com.hp.dao;

import java.util.List;

import com.hp.model.Message;

public interface MessageDao {
    
    //查询所有
    List<Message> findAllMessage();
    //根据Id查询留言
    Message findByMid(Integer mid);
    //删除留言
    Integer deleteMessage(Integer mid);
    //回复留言
    Integer updateMessage(Message message);
    //添加留言
    Integer addMessage(Message message);
}

Mapper映射文件:

UserinfoDaoMapper.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
    PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
    "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="com.hp.dao.UserinfoDao">
     <insert id="add" parameterType="com.hp.model.Userinfo">
         insert into userinfo (uname,upass,urealname,tel,cardId,type,deleteStatus)
         values(#{uname},#{upass},#{urealname},#{tel},#{cardId},0,1)
     </insert>
     <select id="login" resultType="com.hp.model.Userinfo">
         select *  from userinfo where uname=#{uname} and upass=#{upass} and type=#{type} and deleteStatus=1
     </select>

     <select id="findAll" resultType="com.hp.model.Userinfo">
         select * from userinfo where type=0 and deleteStatus=1
     </select>
     <select id="find" resultType="com.hp.model.Userinfo">
         select * from userinfo where type=0 and deleteStatus=1 and uname=#{uname}
     </select>
     <update id="delete" >
         update  userinfo set deleteStatus=0 where userId=#{userId} 
     </update>
     <update id="update" parameterType="com.hp.model.Userinfo">
         update userinfo set uname=#{uname},
             upass=#{upass},
             urealname=#{urealname},
             tel=#{tel},
             cardId=#{cardId}
         where userId=#{userId}
     </update>
</mapper>

NewsDaoMapper.xml

 1 <?xml version="1.0" encoding="UTF-8" ?>
 2 <!DOCTYPE mapper
 3     PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 4     "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 5 
 6 <mapper namespace="com.hp.dao.NewsDao">
 7      
 8      <select id="findAllNews" resultType="com.hp.model.News">
 9          select * from news where type=#{type} and delstatus=1
10      </select>
11      <insert id="addNews" parameterType="com.hp.model.News">
12          insert into news(title,content,savetime,type,imgurl,delstatus)
13          values(#{title},#{content},now(),#{type},#{imgurl},1)
14      </insert>
15      
16 </mapper>

MessageDaoMapper.xml

 1 <?xml version="1.0" encoding="UTF-8" ?>
 2 <!DOCTYPE mapper
 3     PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 4     "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 5 
 6 <mapper namespace="com.hp.dao.MessageDao">
 7      <resultMap type="com.hp.model.Message" id="messageMap">
 8          <id property="mid" column="mid" />
 9         <result property="content" column="content" />
10         <result property="reply" column="reply" />
11         <result property="saveTime" column="saveTime" />
12      <association property="userinfo" javaType="com.hp.model.Userinfo">
13           <id property="userId" column="userId" />
14         <result property="uname" column="uname" />
15         <result property="upass" column="upass" />
16         <result property="urealname" column="urealname" />
17         <result property="tel" column="tel" />
18         <result property="cardId" column="cardId" />
19         <result property="type" column="type" />
20         <result property="deleteStatus" column="deleteStatus" />
21      </association>
22      </resultMap>
23      
24      
25      <select id="findAllMessage" resultType="com.hp.model.Message" resultMap="messageMap">
26          select * from message m 
27          inner join userinfo u 
28          where m.usid =u.userId and delstatus=1
29      </select>
30      <select id="findByMid" resultType="com.hp.model.Message">
31          select *  from  message where mid=#{mid}
32      </select>
33      
34      <insert id="addMessage" parameterType="com.hp.model.Message">
35          insert into message (content,savetime,usid,delstatus) 
36          values(#{content},now(),#{userinfo.userId},1)
37      </insert>
38      <update id="updateMessage" parameterType="com.hp.model.Message">
39          update message set reply=#{reply}
40          where mid=#{mid}
41      </update>
42      <update id="deleteMessage">
43          update message set delstatus=0 where mid=#{mid}
44      </update>
45      
46 </mapper>

业务层Service:

 1 package com.hp.service;
 2 
 3 import java.util.List;
 4 
 5 import org.springframework.beans.factory.annotation.Autowired;
 6 import org.springframework.stereotype.Service;
 7 
 8 import com.hp.dao.MessageDao;
 9 import com.hp.model.Message;
10 
11 @Service
12 public class MessageServiceImpl implements MessageService {
13     @Autowired
14     private MessageDao messageDao;
15     @Override
16     public List<Message> findAllMessage() {
17         return messageDao.findAllMessage();
18     }
19     @Override
20     public Integer deleteMessage(Integer mid) {
21         return messageDao.deleteMessage(mid);
22     }
23     @Override
24     public Integer updateMessage(Message message) {
25         return messageDao.updateMessage(message);
26     }
27     @Override
28     public Integer addMessage(Message message) {
29         return messageDao.addMessage(message);
30     }
31     @Override
32     public Message findByMid(Integer mid) {
33         return messageDao.findByMid(mid);
34     }
35 
36 }
MessageServiceImpl
 1 package com.hp.service;
 2 
 3 import java.util.List;
 4 
 5 import org.springframework.beans.factory.annotation.Autowired;
 6 import org.springframework.stereotype.Service;
 7 
 8 import com.hp.dao.UserinfoDao;
 9 import com.hp.model.Userinfo;
10 @Service
11 public class UserinfoServiceImpl implements UserinfoService {
12     @Autowired
13     private UserinfoDao userinfoDao;
14 
15     @Override
16     public Integer add(Userinfo userinfo) {
17         return userinfoDao.add(userinfo);
18     }
19 
20     @Override
21     public Userinfo login(String uname,String upass,String type) {
22         return userinfoDao.login(uname, upass,type);
23     }
24 
25     @Override
26     public List<Userinfo> findAll() {
27         return userinfoDao.findAll();
28     }
29 
30     @Override
31     public Integer delete(Integer userId) {
32         return userinfoDao.delete(userId);
33     }
34 
35     @Override
36     public Integer update(Userinfo userinfo) {
37         return userinfoDao.update(userinfo);
38     }
39 
40     @Override
41     public Userinfo find(String uname) {
42         return userinfoDao.find(uname);
43     }
44 
45 }
UserinfoServiceImpl
 1 package com.hp.service;
 2 
 3 import java.util.List;
 4 
 5 import org.springframework.beans.factory.annotation.Autowired;
 6 import org.springframework.stereotype.Service;
 7 
 8 import com.hp.dao.NewsDao;
 9 import com.hp.model.News;
10 @Service
11 public class NewsServiceImpl implements NewsService {
12     @Autowired
13     private NewsDao newsDao;
14     @Override
15     public List<News> findAllNews(String type) {
16         return newsDao.findAllNews(type);
17     }
18 
19     @Override
20     public Integer addNews(News news) {
21         return newsDao.addNews(news);
22     }
23 
24 }
NewsServiceImpl

控制层 Controller

 1 package com.hp.controller;
 2 
 3 import java.util.List;
 4 
 5 import javax.servlet.http.HttpServletRequest;
 6 import javax.servlet.http.HttpSession;
 7 
 8 import org.springframework.beans.factory.annotation.Autowired;
 9 import org.springframework.http.HttpRequest;
10 import org.springframework.stereotype.Controller;
11 import org.springframework.web.bind.annotation.RequestMapping;
12 import org.springframework.web.bind.annotation.ResponseBody;
13 
14 import com.alibaba.fastjson.JSONArray;
15 import com.hp.model.Userinfo;
16 import com.hp.service.UserinfoServiceImpl;
17 
18 @Controller
19 public class UserinfoController {
20     
21     @Autowired
22     private UserinfoServiceImpl  userService;
23     
24     //会员添加
25     @RequestMapping(value="/addUser",produces="text/plain;charset=utf-8")
26     public String addUser(Userinfo userinfo){
27         Userinfo find = userService.find(userinfo.getUname());
28         if(find == null){
29             Integer add = userService.add(userinfo);
30             if (add>0) {
31                 return "qlogin.jsp";
32             }
33         }
34         return "register.jsp";
35     }
36     //会员登录
37     @RequestMapping(value="/qlogin",produces="text/plain;charset=utf-8")
38     public String qlogin(HttpSession session,String uname, String upass){
39         Userinfo login = userService.login(uname, upass,"0");
40         if (login!=null) {
41             session.setAttribute("user", login);
42             return "qloginsuccess.jsp";
43         }
44         return "qlogin.jsp";
45     }
46     
47     //管理员添加用户
48     @RequestMapping(value="/add",produces="text/plain;charset=utf-8")
49     public String add(Userinfo userinfo){
50         Integer add = userService.add(userinfo);
51         if (add>0) {
52             return "redirect:/findAll";
53         }
54         return "main.jsp";
55     }
56     //修改会员
57     @RequestMapping(value="/update",produces="text/plain;charset=utf-8")
58     public String update(Userinfo userinfo){
59         Integer update = userService.update(userinfo);
60         if (update>0) {
61             return "redirect:/findAll";
62         }
63         return "main.jsp";
64     }
65     
66     //删除会员
67     @RequestMapping(value="/delete",produces="text/plain;charset=utf-8")
68     public String delete(Integer userId){
69         Integer delete = userService.delete(userId);
70         if (delete>0) {
71             return "redirect:/findAll";
72         }
73         return "main.jsp";
74     }
75     //管理员登录
76     @RequestMapping(value="/login",produces="text/plain;charset=utf-8")
77     public String login(HttpSession session,String uname, String upass){
78         Userinfo login = userService.login(uname, upass,"1");
79         if (login!=null) {
80             session.setAttribute("admin", login);
81             return "main.jsp";
82         }
83         return "login.jsp";
84     }
85     //管理员查看所有会员信息
86     @RequestMapping(value="/findAll",produces="text/plain;charset=utf-8")
87     public String findAll(HttpSession session){
88         List<Userinfo> list = userService.findAll();
89         if (list!=null) {
90             session.setAttribute("listUser", list);
91             return "index.jsp";
92         }
93         return "login.jsp";
94     }
95     
96     
97 
98 }
UserinfoController
 1 package com.hp.controller;
 2 
 3 import java.io.File;
 4 import java.io.IOException;
 5 import java.util.List;
 6 
 7 import javax.servlet.http.HttpServletRequest;
 8 import javax.servlet.http.HttpSession;
 9 
10 import org.apache.commons.fileupload.servlet.ServletFileUpload;
11 import org.springframework.beans.factory.annotation.Autowired;
12 import org.springframework.http.HttpRequest;
13 import org.springframework.stereotype.Controller;
14 import org.springframework.web.bind.annotation.RequestMapping;
15 import org.springframework.web.bind.annotation.RequestParam;
16 import org.springframework.web.multipart.MultipartFile;
17 import org.springframework.web.multipart.MultipartHttpServletRequest;
18 import org.springframework.web.util.WebUtils;
19 
20 import com.hp.model.News;
21 import com.hp.service.NewsServiceImpl;
22 
23 @Controller
24 public class NewsController {
25     @Autowired
26     private NewsServiceImpl newsService;
27     //前台浏览信息
28     @RequestMapping(value="qfindAllNews",produces="text/plain;charset=utf-8")
29     public String qfindAllNews(HttpSession session,String type){
30         List<News> list = newsService.findAllNews(type);
31         if (list.size()>0) {
32             session.setAttribute("newsList", list);
33             if(type.equals("0")){
34                 return "qnotice.jsp";
35             }else{
36                 return "qnews.jsp";
37             }
38             
39         }
40         return "main.jsp";
41     }
42     //后台管理查询信息
43     @RequestMapping(value="findAllNews",produces="text/plain;charset=utf-8")
44     public String findAllNews(HttpSession session,String type){
45         List<News> list = newsService.findAllNews(type);
46         if (list.size()>0) {
47             session.setAttribute("newslist", list);
48             if(type.equals("0")){
49                 return "notice.jsp";
50             }else{
51                 return "news.jsp";
52             }
53             
54         }
55         return "main.jsp";
56     }
57     //后台发布信息
58     @RequestMapping(value="addNews",produces="text/plain;charset=utf-8")
59     public String addNews(HttpServletRequest request,String type,News news){
60         MultipartFile multipartFile = null;
61         boolean isMultipart = ServletFileUpload.isMultipartContent(request);
62         if (isMultipart){ 
63             MultipartHttpServletRequest multipartRequest = WebUtils.getNativeRequest(request, MultipartHttpServletRequest.class);
64             multipartFile = multipartRequest.getFile("myFile");
65         }
66 
67         //文件上传到的位置
68         String path = request.getSession().getServletContext().getRealPath("picture");  
69         //上传的文件名
70         String fileName = multipartFile.getOriginalFilename();    
71         File dir = new File(path,fileName); 
72         //判断文件夹是否存在
73         if(!dir.exists()){  
74             dir.mkdirs();  
75         }  
76         //保存  
77         try {
78             multipartFile.transferTo(dir);
79         } catch (IllegalStateException e) {
80             e.printStackTrace();
81         } catch (IOException e) {
82             e.printStackTrace();
83         }  
84         news.setImgurl(fileName);
85         Integer addNews = newsService.addNews(news);
86         if (addNews>0) {
87             return "redirect:/findAllNews?type="+type;
88         }
89         return "tab.jsp";
90     }
91 }
NewsController
 1 package com.hp.controller;
 2 
 3 import java.util.List;
 4 
 5 import javax.servlet.http.HttpSession;
 6 
 7 import org.springframework.beans.factory.annotation.Autowired;
 8 import org.springframework.stereotype.Controller;
 9 import org.springframework.web.bind.annotation.RequestMapping;
10 
11 import com.hp.model.Message;
12 import com.hp.model.Userinfo;
13 import com.hp.service.MessageServiceImpl;
14 
15 @Controller
16 public class MessageController {
17     @Autowired
18     private MessageServiceImpl messageService;
19     
20     //后台查询所有留言
21     @RequestMapping(value="/findAllMessage",produces="text/plain;charset=utf-8")
22     public String findAllMessage(HttpSession session,String str){
23         List<Message> list = messageService.findAllMessage();
24         session.setAttribute("messageList", list);
25         if(list.size()>0){
26             if(str.equals("opr")){
27                 return "quserMessage.jsp";
28             }else{
29                 return "adminMessage.jsp";
30             }
31         }
32         return "main.jsp";
33     }
34     
35     //前台添加留言
36     @RequestMapping(value="/addMessage",produces="text/plain;charset=utf-8")
37     public String addMessage(Message message,HttpSession session){
38             Userinfo userinfo = (Userinfo)session.getAttribute("user");
39             if(userinfo == null){
40                 return "addMessage.jsp";
41             }
42              message.setUserinfo(userinfo);
43              Integer addMessage = messageService.addMessage(message);
44              if(addMessage >0){
45                  return "redirect:/findAllMessage?str=opr";
46             }
47             return "qloginsuccess.jsp";
48         }
49     //后台删除留言
50     @RequestMapping(value="/deleteMessage",produces="text/plain;charset=utf-8")
51     public String deleteMessage(Integer mid){
52              Integer deleteMessage = messageService.deleteMessage(mid);
53              if(deleteMessage >0){
54                  return "redirect:/findAllMessage?str=null";
55             }
56             return "main.jsp";
57     }
58     //后台回复留言
59     @RequestMapping(value="/updateMessage",produces="text/plain;charset=utf-8")
60     public String updateMessage(Message message){
61              Integer updateMessage = messageService.updateMessage(message);
62              if(updateMessage>0){
63                  return "redirect:/findAllMessage?str=null";
64             }
65             return "main.jsp";
66     }
67     //后台根据id查询留言
68         @RequestMapping(value="/findByMid",produces="text/plain;charset=utf-8")
69         public String findByMid(HttpSession session,Integer mid){
70                 Message findByMid = messageService.findByMid(mid);
71                 if(findByMid!=null){
72                     session.setAttribute("message", findByMid);
73                      return "updateMessage.jsp";
74                 }
75                 return "main.jsp";
76         }
77 
78 }
MessageController

前台登录页面

 

 

 

1 <form action="qlogin" method="post"><div class="content">
2         <div class="field"><label>账 户:</label><input class="username" name="uname" type="text" /></div>
3         <div class="field"><label>密 码:</label><input class="password" name="upass" type="password" /><br /></div>
4         <div class="btn"><input name="" type="submit" class="login-btn" value="" /></div>
5       </div></form>
qlogin.jsp

 1 <form action="addUser" onsubmit = "return check()" method="post">
 2         <dl>
 3             <div id="error"> ${error }</div>
 4             <dt>用 户 名:</dt>
 5             <dd><input type="text" name="uname" id="username"/></dd>
 6             <dt>密  码:</dt>
 7             <dd><input type="password" name="upass" id="password" /></dd>
 8             <dt>确认密码:</dt>
 9             <dd><input type="password" name="affirm" id="affirm" /></dd>
10             <dt>真实姓名:</dt>
11             <dd><input type="text" name="urealname" id="urealname"/></dd>
12             <dt>电话:</dt>
13             <dd><input type="text" name="tel" id="tel"/></dd>
14             <dt>身 份 证:</dt>
15             <dd><input type="text" name="cardId" id="cardId"/></dd>
16         </dl>
17         <div class="buttons">
18             <input class="btn-reg png" type="submit" name="register" value=" " /><input class="btn-reset png" type="reset" name="reset" value=" " />
19         </div>
20         <div class="goback"><a href="qlogin.jsp" class="png">返回登录页</a></div>
21     </form>
register.jsp

 

 

 

<ul class="forminfo" >
    <li><label>账户名</label><input name="uname" type="text" class="dfinput" value="${user.uname }"/></li>
    <li><label>密码</label><input name="upass" type="text" class="dfinput" value="${user.upass }"/></li>
    <li><label>真实姓名</label><cite><input name="urealname" type="text" value="${user.urealname }" class="dfinput"/></cite></li>
    <li><label>电话号码</label><input name="tel" type="text" class="dfinput" value="${user.tel }" /></li>
    <li><label>身份证</label><input name="cardId" type="text" class="dfinput" value="${user.cardId }" /></li>
    <li><label>&nbsp;</label><input name="" type="submit" class="btn" value="确认修改" style="background: #42B0E3"/></li>
    </ul>

 

  

 

 1  <div class="formtitle"><span>公告列表</span></div>
 2     
 3     <table class="tablelist">
 4         <tr>
 5         <th>公告编号<i class="sort"><img src="images/px.gif" /></i></th>
 6         <th>公告标题</th>
 7         <th>公告内容</th>
 8         <th>发布时间</th>
 9         </tr>
10               <c:forEach var="news" items="${newslist }" varStatus="sta">
11                   <tr>
12                       <td>${sta.count }</td>
13                       <td>${news.title}</td>
14                       <td>${news.content}</td>
15                       <td>${news.savetime}</td>
16                   </tr>
17               </c:forEach>
18     </table>
notice.jsp

 

 

 

 1  <div class="formtitle"><span>新闻列表</span></div>
 2     <table class="imgtable">  
 3     <tr>    
 4     <th>缩略图</th>
 5     <th>新闻标题</th>
 6     <th>新闻内容</th>
 7     <th>发布时间</th>
 8     </tr>    
 9       <c:forEach var="news" items="${newslist }">
10               <tr>
11                   <td class="imgtd"><img  src="picture/${news.imgurl}" width="50px;"/></td>
12                   <td>${news.title}</td>
13                   <td>${news.content}</td>
14                   <td>${news.savetime}</td>
15               </tr>
16     </c:forEach>    
17   </table>
news.jsp

 

 

 

 1 <table class="table table-bordered table-hover">
 2                 <thead>
 3                     <tr>
 4                         <th>
 5                             编号
 6                         </th>
 7                         <th>
 8                             内容
 9                         </th>
10                         <th>
11                             回复
12                         </th>
13                         <th>
14                             发布时间
15                         </th>
16                         <th>
17                             用户名
18                         </th>
19                     </tr>
20                 </thead>
21                 <tbody>
22                  <c:forEach var="message" items="${messageList }" varStatus="sta">
23                      <tr>
24                         <td>${sta.count}</td>
25                         <td>${message.content }</td>
26                         <td>${message.reply }</td>
27                         <td>${message.saveTime }</td>
28                         <td>${message.userinfo.uname }</td>
29                      </tr>
30                  </c:forEach>
31                     
32                 </tbody>
33             </table>
quserMessage.jsp

 

 

 1 <form role="form" action="addMessage" method="post" >
 2             <div class="form-group">
 3                 <label for="name">留言板提问:</label>
 4                 <textarea class="form-control" rows="13" name="content"></textarea>
 5             <c:if test="${user==null }">
 6                  <div class="row clearfix">
 7                     <div class="col-md-12 column">
 8                          <button type="button" class="btn  btn-default disabled" style="background:gray;color:white;margin-top: 5px;">提交留言</button>
 9                          <a href="qlogin.jsp" target="_parent" style="color: red">请登录后,提交留言</a>
10                     </div>
11                 </div>
12             </c:if>
13             <c:if test="${user!=null }">
14                  <div class="row clearfix">
15                     <div class="col-md-12 column">
16                          <button type="submit" class="btn  btn-default" style="background:#42B0E3;color:white;margin-top: 5px;">提交留言</button>
17                     </div>
18                 </div>
19             </c:if>
20             </div>
21         </form>
addMessage.jsp

后台页面:

  

 

 

 

<form method="post" action="login">
        <ul>
        <li><input name="uname" type="text" class="loginuser" value="admin" onclick="JavaScript:this.value=''"/></li>
        <li><input name="upass" type="text" class="loginpwd" value="密码" onclick="JavaScript:this.value=''"/></li>
        <li><input name="" type="submit" class="loginbtn" value="登录"    /><label><input name="" type="checkbox" value="" checked="checked" />记住密码</label><label><a href="#">忘记密码?</a></label></li>
        </ul>
    </form>
login.jsp

 

 

 

1 <frameset rows="88,*,31" cols="*" frameborder="no" border="0" framespacing="0">
2   <frame src="top.jsp" name="topFrame" scrolling="no" noresize="noresize" id="topFrame" title="topFrame" />
3   <frameset cols="187,*" frameborder="no" border="0" framespacing="0">
4     <frame src="left.jsp" name="leftFrame" scrolling="no" noresize="noresize" id="leftFrame" title="leftFrame" />
5     <frame src="findAll" name="rightFrame" id="rightFrame" title="rightFrame" />
6   </frameset>
7   <frame src="footer.html" name="bottomFrame" scrolling="no" noresize="noresize" id="bottomFrame" title="bottomFrame" />
8 </frameset>
main.jsp
 1 <li>
 2             <div class="header">
 3             <cite></cite>
 4             <a href="findAll" target="rightFrame">会员管理</a>
 5             <i></i>
 6             </div>
 7             <ul class="sub-menus">
 8             <li><a href="findAll" target="rightFrame">查询所有用户</a></li>
 9             <li><a href="addUser.jsp" target="rightFrame">添加用户</a></li>
10             <li><a href="updateAdmin.jsp" target="rightFrame">个人资料修改</a></li>
11             </ul>
12         </li>
left.jsp

 

 1             <table class="table table-bordered table-hover">
 2                 <thead>
 3                     <tr>
 4                         <th>
 5                             编号
 6                         </th>
 7                         <th>
 8                             内容
 9                         </th>
10                         <th>
11                             回复
12                         </th>
13                         <th>
14                             发布时间
15                         </th>
16                         <th>
17                             用户名
18                         </th>
19                         
20                         <th>
21                             操作
22                         </th>
23                     </tr>
24                 </thead>
25                 <tbody>
26                  <c:forEach var="message" items="${messageList }" varStatus="sta">
27                      <tr>
28                         <td>${sta.count}</td>
29                         <td>${message.content }</td>
30                         <td>${message.reply }</td>
31                         <td>${message.saveTime }</td>
32                         <td>${message.userinfo.uname }</td>
33                         <td><input type="button"  value="删除" onclick="del(${message.mid})" style="width: 50px;height:30px;background:#FFDCA9"/> 
34                         <input type="button"  value="回复" onclick="update(${message.mid})" style="width: 50px;height:30px;background:#FFDCA9"/> </td>
35                      </tr>
36                  </c:forEach>
37                 </tbody>
38             </table>
adminMessage.jsp

 

 

 

 1     <div id="tab1" class="tabson">
 2     <div class="formtext">Hi,<b>${admin.uname }</b>,欢迎您试用公告发布功能!</div>
 3      <form action="addNews?type=0" method="post">
 4         <ul class="forminfo">
 5         <li><label>公告标题<b>*</b></label><input name="title" type="text" class="dfinput" value="请填写公告标题"  style="width:518px;"/></li>
 6         <li><label>公告内容<b>*</b></label>
 7         <textarea id="content7" name="content" style="width:700px;height:250px;visibility:hidden;"></textarea>
 8         </li>
 9         <li><label>&nbsp;</label><input name="" type="submit" class="btn" value="马上发布"/></li>
10         </ul>
11     </form>
12     </div> 
13       <div id="tab2" class="tabson">
14     <form action="addNews?type=1" method="post" enctype="multipart/form-data">
15            <ul class="forminfo">
16             <li><label>文章标题</label><input name="title" type="text" class="dfinput" /><i>标题不能超过30个字符</i></li>
17             <li><label>文章图片</label><input name="myFile" type="file"  /></li>
18             <li><label>文章内容</label><textarea name="content" cols="" rows="" class="textinput"></textarea></li>
19             <li><label>&nbsp;</label><input name="" type="submit" class="btn" value="马上发布"/></li>
20           </ul>
21      </form>
22     </div>  
tab.jsp

 

 

 

 1  <div class="formtitle"><span>公告列表</span></div>
 2     <table class="tablelist">
 3         <tr>
 4         <th>公告编号<i class="sort"><img src="images/px.gif" /></i></th>
 5         <th>公告标题</th>
 6         <th>公告内容</th>
 7         <th>发布时间</th>
 8         </tr>
 9               <c:forEach var="news" items="${newslist }" varStatus="sta">
10                   <tr>
11                       <td>${sta.count }</td>
12                       <td>${news.title}</td>
13                       <td>${news.content}</td>
14                       <td>${news.savetime}</td>
15                   </tr>
16               </c:forEach>
17     </table>
notice.jsp
 1     <div class="formtitle"><span>新闻列表</span></div>
 2     <table class="imgtable">
 3     <tr>
 4     <th>缩略图</th>
 5     <th>新闻标题</th>
 6     <th>新闻内容</th>
 7     <th>发布时间</th>
 8     </tr>
 9       <c:forEach var="news" items="${newslist }">
10               <tr>
11                   <td class="imgtd"><img  src="picture/${news.imgurl}" width="50px;"/></td>
12                   <td>${news.title}</td>
13                   <td>${news.content}</td>
14                   <td>${news.savetime}</td>
15               </tr>
16     </c:forEach>
17     </table>
18     
news.jsp

三、遇到的问题:

  a.前台页面只有会员才能预定跟车票相关业务,游客不可以,游客可以留言管理员发布的相关信息

  b.后台只有登录才可以查看,游客无法查看

四、解决办法

  a.游客需要预定车票相关业务的时候,需要先判断会话里面是否有用户,如果没有就跳转到登录页面并进行登录,登录完成后保存信息到会话里面。

  b.后台访问主页面的时候,也需要判断会话里面是否包含用户信息,如果没有跳转到登录页面进行登录,登录完成后保存信息到会话里面。

 

posted on 2020-07-17 10:59  淳真淼淼  阅读(187)  评论(0编辑  收藏  举报