package com.web.common.filter;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import com.web.member.model.vo.Member;
@WebFilter(servletNames= {
"memberView"
})
public class CheckAthunticate extends HttpFilter implements Filter {
public CheckAthunticate() {
super();
}
public void destroy() {
}
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpSession session = ((HttpServletRequest)request).getSession();
Member loginMember=(Member)session.getAttribute("loginMember");
if(loginMember==null|| !loginMember.getUserId().equals(request.getParameter("userId"))){
request.setAttribute("msg", "잘못된 접근입니다.");
request.setAttribute("loc", "/");
request.getRequestDispatcher("/views/common/msg.jsp").forward(request, response);
}else {
chain.doFilter(request, response);
}
}
public void init(FilterConfig fConfig) throws ServletException {
}
}
package com.web.member.controller;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.web.common.AESEncryptor;
import com.web.member.model.vo.Member;
import com.web.member.service.MemberService;
@WebServlet(name="memberView", urlPatterns="/member/memberView.do")
public class MemberViewSerlvet extends HttpServlet {
private static final long serialVersionUID = 1L;
public MemberViewSerlvet() {
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String userId=request.getParameter("userId");
System.out.println(userId);
Member m = new MemberService().selectByUserId(userId);
try {
m.setEmail(AESEncryptor.decryptData(m.getEmail()));
}catch(Exception e) {
}
try {
m.setPhone(AESEncryptor.decryptData(m.getPhone()));
}catch(Exception e) {
}
request.setAttribute("infoMember",m);
request.getRequestDispatcher("/views/member/memberView.jsp")
.forward(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
}