ÔÚJSPÀïµ÷ÓÃspring¹ÜÀíµÄbeanÈ¡µÃÊý¾Ý
Ò»£ºweb.xmlÅäÖÃ
<servlet>
<servlet-name>context</servlet-name>
<servlet-class>
org.springframework.web.context.ContextLoaderServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
¶þ£ºÔÚJSP
<%@ page import="org.springframework.context.ApplicationContext"%>
<%@ page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@ page import="com.yourcompany.service.CategoryService"%>
<%
//ÉÏÃæµÄCategoryServiceÒýÓÃÊÇÎÒ×Ô¼ºµÄ¶«Î÷
//applicationContext.xmlÖÐÒ»¶¨ÒªÓÐÍêÕûµÄÒÀÀµÁ´£¬´ÓdataSourceµ½CategoryService
ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(request.getSession().getServletContext());
CategoryService cs = (CategoryService) ctx.getBean("CategoryService");
List list =cs.getCategoryDAO().findAll();
%>
Ïà¹ØÎĵµ£º
ÔÚÌÚ¿ÆÅàѵÁËÓÐ1¸ö°ëÔÂÁË£¬ÖÕÓÚѧÍêJSP+SERVLET+JAVABEAN+MYSQL£¬Ñ§ÁËjavaµÄµÚÒ»Ì×web½â¾ö·½°¸¡£ÀÏʦҪÇóÎÒÃÇ6ÈËÒ»×鿪ʼ×öÒ»¸ö¶©²Íϵͳ¡£Õâ¸öϵͳûÓÐʲôÌرðµÄ£¬¾Í¸úµç×ÓÉ̳ÇÊÇÒ»¸öÑùµÄ¡£ÓÉÓÚÒª¶ÔÊý¾Ý¿â×ö´óÁ¿µÄÔöɾ¸Ä²é£¬ÄǸö´úÂëÓֶ࣬ÎÒÏëÄܲ»Äܽ«Êý¾Ý¿â²Ù×÷µÄÕâÒ»²ã´ò°üÆðÀ´(SqlOperDao)£¬ÈÃÎÒ¶ÔÊý¾Ý¿â²Ù×÷£¬Óü¸Ðд ......
ÓÃJSP¹¹½¨¶¯Ì¬ÍøÕ¾ ËïÒÔÒå ¶Å¾é
Ò»¡¢ ʲôÊÇJSP JSP(JavaServer Pages)ÊÇÓÉSun Microsystems¹«Ë¾³«µ¼¡¢Ðí¶à¹«Ë¾²ÎÓëÒ»Æð½¨Á¢µÄÒ»ÖÖ¶¯Ì¬ÍøÒ³¼¼Êõ±ê×¼£¬ÆäÍøַΪ
http://www.javasoft.com/products/jsp¡£ ÔÚ´«Í³µÄÍøÒ³HTMLÎļþ(*.htm,*.html)ÖмÓÈëJava³ÌÐòƬ¶Î(Scriptlet)ºÍJSP±ê¼Ç(tag)£¬¾Í¹¹
³ÉÁËJSPÍøÒ³(*.jsp)¡£Web· ......
×î»ù±¾µÄÂÒÂëÎÊÌâ
Õâ¸öÂÒÂëÎÊÌâÊÇ×î¼òµ¥µÄÂÒÂëÎÊÌâ¡£Ò»°ãлá³öÏÖ¡£¾ÍÊÇÒ³Ãæ±àÂë²»Ò»Öµ¼ÖµÄÂÒÂë¡£
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ page contentType="text/html;charset=iso8859-1"%>
<html>
<head>
<title>ÖÐÎÄÎÊÌâ</title>
<meta http-equiv="Co ......
ÔÚÒ»¸ö´óÐÍÏîÄ¿ÖÐÍùÍùÓжà¸öservlet¹ýÂËÆ÷£¬µ«ÊÇÕâЩservlet¹ýÂËÆ÷µÄÖ´ÐÐ˳ÐòÊÇÔõÑùµÄÄØ£¿ ÏîÄ¿ÖйØÓÚSSH2ÖÐOpenSessionInViewFilterµÄѧϰÑо¿£¬²âÊÔFilterµÄÏȺó˳Ðò£¡£¡
Çë¿´Ò»ÏÂÀý×Ó£º
´´½¨Á½¸ö¼òµ¥µÄservletÎļþ
package filter;
import java.io.IOException;
import javax.servlet.Filt ......
1.RequestDispatcher.forward()
ÊÇÔÚ·þÎñÆ÷¶ËÆð×÷ÓÃ,µ±Ê¹ÓÃforward()ʱ,Servlet engine´«µÝHTTPÇëÇó´Óµ±Ç°µÄServlet or JSPµ½ÁíÍâÒ»¸öServlet,JSP »òÆÕͨHTMLÎļþ,Ò²¼´ÄãµÄformÌá½»ÖÁa.jsp,ÔÚa.jspÓõ½ÁËforward()Öض¨ÏòÖÁb.jsp,´ËʱformÌá½»µÄËùÓÐÐÅÏ¢ÔÚb.jsp¶¼¿ÉÒÔ»ñµÃ,²ÎÊý×Ô¶¯´«µÝ.
µ«forward()ÎÞ·¨Öض ......