jspµÇ½·ÃÎÊÌø×ª
δµÇ½£¬½ûÖ¹·ÃÎÊÈκÎÒ³Ãæ£¬×Ô¶¯Ìø×ªµ½µÇ½ҳ
package com.catalogeasy.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.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class LoginFilter implements Filter {
public void destroy() {
// TODO Auto-generated method stub
}
public void doFilter(ServletRequest arg0, ServletResponse arg1,
FilterChain arg2) throws IOException, ServletException {
// TODO Auto-generated method stub
HttpServletRequest httprequest = (HttpServletRequest) arg0;
HttpServletResponse httpresponse = (HttpServletResponse) arg1;
String temp = httprequest.getServletPath();
if(httprequest.getSession().getAttribute("user")==null){
if("/jdom.do".equals(temp)||"/login.do".equals(temp)){
arg2.doFilter(arg0, arg1);
}else{
httpresponse.sendRedirect("/CatalogUser");
}
}else{
arg2.doFilter(arg0, arg1);
}
/*if(httprequest.getSession().getAttribute("user")==null&&((!"/jdom.do".equals(temp))||(!"/login.do".equals(temp)))){
httpresponse.sendRedirect("/CatalogUser/user/login.jsp");
}else{
arg2.doFilter(arg0, arg1);
}*/
}
public void init(FilterConfig arg0) throws ServletException {
// TODO Auto-generated method stub
}
2.µÇ½ºóÌø×ªµ½ÇëÇóÒ³Ãæ
import java.io.IOException;
import java.net.URLEncoder;
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.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import
Ïà¹ØÎĵµ£º
<?xml version="1.0" encoding="gb2312" ?>
<?xml-stylesheet type="tet/css" href="mystyle.css" ?>
<%@ page errorPage="error.jap" %>
<%@ page contentType="text/xml" %>
<realmarid>
»ÊÂí»¨Ãû²á
<athlete>
<name>Æë´ïÄÚ</name>
<country> ......
Ò»Ö±¶ÔServletµÄ¼¸ÖÖÒ³ÃæÌø×ª·½Ê½£¬Àí½âµÄºýÀïºýÍ¿µÄ£¬½ñÌìÔÚÍøÉÏËÑÁËÒ»°Ñ£¬ÕÒµ½Ò»±é±È½ÏºÃµÄ£¬¼ÇÏÂÀ´£¬ÒÔºó¿´¿´¡£
Ìø×ª·ÖÁ½²¿·Ö£¬Ò»ÊÇ·¢ÉúÔÚservlet£¬Ò»ÊÇÔÚJSP£¬ÆäʵJSPÒ²¾ÍÊÇservlet£¬²»¹ý»¹ÊÇÓеã²îÒìµÎ¡£
Servlet£º
µ±È»£¬ÔÚservletÖУ¬Ò»°ãÌø×ª¶¼·¢ÉúÔÚdoGet, doPostµÈ·½·¨ÀïÃæ¡£
1) redirect · ......
»·¾³ÅäÖúú󣬿ª·¢JSP³ÌÐò¾Í·Ç³£¼òµ¥ÁË¡£
File-->New-->Web Project
Ôڸô°¿ÚÖÐÊäÈëһЩ¹¤³Ì»ù±¾ÐÅÏ¢£¬±ÈÈ繤³ÌÃû£¬ÕâÀïÊäÈëΪ test1-01
ÕâÑùÒ»¸ö»ùÓÚJSPµÄÏîÄ¿¾Í½¨Á¢ÆðÀ´ÁË¡£
Package Explorer µÄÏÔʾ·½·¨£º
Windows-->Show View-->Package Explorer ÕâÑù¾ÍÄÜÏÔʾ³öÀ´À²£¡
Ï ......
public static List getPageUser(int currentPage) throws Exception {//?List
Connection conn = null;
PreparedStatement prep = null;
ResultSet rs = null ......
1.Ê×ÏÈÃ÷È·Á½¸ö¸ÅÄ
·þÎñÆ÷·¾¶£ºÐÎÈ磺http://192.168.0.1/µÄ·¾¶
WebÓ¦Ó÷¾¶£ºÐÎÈ磺http://192.168.0.1/yourwebappµÄ·¾¶
2.¹ØÓÚÏà¶Ô·¾¶Óë¾ø¶Ô·¾¶µÄÃèÊö£º
ServletÖУ¬"/"´ú±íWebÓ¦ÓõĸúĿ¼¡£ºÍÎïÀí·¾¶µÄÏà¶Ô±íʾ¡£ÀýÈ磺"./" ´ú±íµ±Ç°Ä¿Â¼, "../"´ú±íÉϼ¶Ä¿Â¼¡£ÕâÖÖÀàËÆµÄ±íʾ£¬Ò²ÊÇÊôÓÚÏà¶Ô·¾¶¡£Õâ ......