一些代码模板

	@Override
	public void doFilter(ServletRequest sRequest, ServletResponse sResponse, FilterChain filterChain) throws IOException, ServletException {
		/* 准备 */
		HttpServletRequest request = (HttpServletRequest) sRequest;
		HttpServletResponse response = (HttpServletResponse) sResponse;
		HttpSession session=request.getSession();
		/* 获得数据 */
		String expression = request.getParameter("expression");
		System.out.println("expression:"+expression);

		/*
		filterChain.doFilter(request, response);

		dispatcher = request.getRequestDispatcher("/error_exp.jsp");
		dispatcher.forward(request, response);
		return;
		*/

	}

 

Filter过滤jsp:

 

	<filter>
		<filter-name>ExpValidateFilter</filter-name>
		<filter-class>com.macrotea.dev.filter.ExpValidate</filter-class>
	</filter>
	<filter-mapping>
		<filter-name>ExpValidateFilter</filter-name>
		<url-pattern>/result.jsp</url-pattern>
	</filter-mapping>

  

 

Servlet的url-pattern的jsp:

 

	<servlet>
		<servlet-name>Password_Validate</servlet-name>
		<jsp-file>/check.jsp</jsp-file>
		<init-param>
			<param-name>secret</param-name>
			<param-value>137280</param-value>
		</init-param>
	</servlet>
	<servlet-mapping>
		<servlet-name>Password_Validate</servlet-name>
		<url-pattern>/check.jsp</url-pattern>
	</servlet-mapping>

 

Filter过滤Servlet:

	<filter>
		<filter-name>LoginValidateFilter</filter-name>
		<filter-class>com.macrotea.school.filter.LoginValidate</filter-class>
		<init-param>
			<param-name>hi</param-name>
			<param-value>good</param-value>
		</init-param>
	</filter>
	<filter-mapping>
		<filter-name>LoginValidateFilter</filter-name>
		<servlet-name>StudentList</servlet-name>
	</filter-mapping>

 

常规Servlet:

	<servlet>
		<servlet-name>StudentBound</servlet-name>
		<servlet-class>com.macrotea.school.servlet.StudentBound</servlet-class>
		<init-param>
			<param-name>hi</param-name>
			<param-value>good</param-value>
		</init-param>
	</servlet>
	<servlet-mapping>
		<servlet-name>StudentBound</servlet-name>
		<url-pattern>/servlet/studentbound.do</url-pattern>
	</servlet-mapping>

 

常规Filte

	<filter>
		<filter-name>LoginValidateFilter</filter-name>
		<filter-class>com.macrotea.school.filter.LoginValidate</filter-class>
		<init-param>
			<param-name>hi</param-name>
			<param-value>good</param-value>
		</init-param>
	</filter>
	<filter-mapping>
		<filter-name>LoginValidateFilter</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>

 r:

 

你可能感兴趣的:(jsp,servlet)