Spring运行在tomcat上
2021-06-20 14:05
YPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
æ ç¾ï¼ç¬¬ä¸ä¸ªÂ   get   text   classpath   frame   ack   pack   meta   html 4.01  Â
å¨Spring第ä¸ä¸ªDemoç¨åºçåºç¡ä¸
ç¬¬ä¸æ¥ï¼æ·»å web.xmlæä»¶ï¼ web.xmlæä»¶æ¾å¨/WEB-INFä¸ï¼å 容å¦ä¸
contextConfigLocation classpath:applicationContext.xml org.springframework.web.context.ContextLoaderListener
ãã该xmlå¨tomcatè¿è¡æ¶ï¼ä¼è¢«å è½½ï¼å¹¶ä¸ä¼æapplicationContext.xmlè¿è¡å è½½
ç¬¬äºæ¥ï¼æ·»å StudentServletç±»
package com.fd.spring.servlet;
import java.io.IOException;
import javax.servlet.ServletConfig;
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 org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
@WebServlet("/student")
public class StudentServlet extends HttpServlet{
@Override
public void init(ServletConfig config) throws ServletException {
super.init(config);
WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
}
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
System.out.println("service...");
req.setAttribute("list", "123");
req.getRequestDispatcher("index.jsp").forward(req, resp);
}
}
ããè¿æ¶è¿è¡run on serverçè¯ï¼å¨é¡µé¢ä¸è®¿é®Â http://localhost:8080/SpringDemo/studentï¼å¨consoleä¸å¯ä»¥çå°å¦ä¸ä¿¡æ¯

Â
ç¬¬ä¸æ¥ï¼ç»§ç»æ·»å index.jsp
Insert title here this is spring on Tomcat
ãã忬¡è¿è¡åºç°å¦ä¸é¡µé¢

Â
Springè¿è¡å¨tomcatä¸
æ ç¾ï¼ç¬¬ä¸ä¸ªÂ   get   text   classpath   frame   ack   pack   meta   html 4.01  Â
åæå°åï¼https://www.cnblogs.com/spark-quant/p/9688642.html
上一篇:Leetcode 125.验证回文串 By Python
下一篇:选择排序