乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      jsp中script引入url項(xiàng)目名${appName}或${app}等

       一本正經(jīng)地胡鬧 2019-05-28

      <script src="/${appName}/commons/jslib/CommonValue.js"></script>

      新建一個(gè)com.autumn.servlet.Dispatcher.java文件

      復(fù)制代碼
      package com.autumn.servlet;
      
      import javax.servlet.ServletConfig;
      import javax.servlet.ServletException;
      
      /**
       * Created by Administrator on 2018/6/6.
       */
      public class Dispatcher extends org.springframework.web.servlet.DispatcherServlet {
          private static final long serialVersionUID = -7677752525845571027L;
          @Override
          public void init(ServletConfig config) throws ServletException {
              super.init(config);
              String appName = config.getInitParameter("appName").trim();     //web.xml中初始化參數(shù)
              config.getServletContext().setAttribute("appName", appName);   //將這個(gè)appName放入servletContext中
          }
      }
      復(fù)制代碼

       

      復(fù)制代碼
          <!-- springmvc的前端控制器 -->
          <servlet>
              <servlet-name>bookkeep-web</servlet-name>
              <servlet-class>com.autumn.servlet.Dispatcher</servlet-class>   <!--原來為org.springframework.web.servlet.DispatcherServlet-->
              <!-- contextConfigLocation不是必須的, 如果不配置contextConfigLocation, springmvc的配置文件默認(rèn)在:WEB-INF/servlet的name+"-servlet.xml" -->
              <init-param>
                  <param-name>contextConfigLocation</param-name>
                  <param-value>classpath:spring/Springmvc.xml</param-value>
              </init-param>
              <init-param>
                  <param-name>appName</param-name>
                  <param-value>Bookkeeping</param-value>
              </init-param>
              <load-on-startup>1</load-on-startup>
          </servlet>
          <servlet-mapping>
              <servlet-name>bookkeep-web</servlet-name>
              <!-- 攔截所有請(qǐng)求jsp除外 -->
              <url-pattern>/</url-pattern>
          </servlet-mapping>
      復(fù)制代碼

      Springmvc.xml

      復(fù)制代碼
      <?xml version="1.0" encoding="UTF-8"?>
      <beans xmlns="http://www./schema/beans"
             xmlns:xsi="http://www./2001/XMLSchema-instance" xmlns:p="http://www./schema/p"
             xmlns:context="http://www./schema/context"
             xmlns:mvc="http://www./schema/mvc"
             xsi:schemaLocation="http://www./schema/beans http://www./schema/beans/spring-beans-4.2.xsd
              http://www./schema/mvc http://www./schema/mvc/spring-mvc-4.2.xsd
              http://www./schema/context http://www./schema/context/spring-context-4.2.xsd">
          <!-- 掃描controller驅(qū)動(dòng) -->
          <context:component-scan base-package="com.autumn.controller" />
          <!-- 注解驅(qū)動(dòng) -->
          <mvc:annotation-driven />
      
          <!--controller返回的視圖解析器,例如返回login,實(shí)際解析為http://ip:port/projectName/WEB-INF/jsp/login.jsp-->
          <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
              <property name="prefix" value="/WEB-INF/jsp/" />
              <property name="suffix" value=".jsp" />
          </bean>
      </beans>
      復(fù)制代碼

      Controler測試

      復(fù)制代碼
      @Controller
      @RequestMapping("/loginController")
      public class LoginController {
          @Autowired
          public LoginService loginService;
      
          @RequestMapping("/login/{id}")
          @ResponseBody   //將返回的對(duì)象解析成json字符串
          public Account login(@PathVariable String id){
              Account account = loginService.login(id);
              return account;   //返回json字符串
          }
      
          @RequestMapping("/loginpage/{id}")
          public String loginpage(@PathVariable String id){
              Account account = loginService.login(id);
              if (account==null) {
                  return "login";   //返回springmvc中配置的/WEB-INF/jsp/login.jsp
              }else {
                  return "index";    //返回springmvc中配置的/WEB-INF/jsp/index.jsp
              }
          }
      }
      復(fù)制代碼

      其他方法

      不用統(tǒng)一管理的${appName}可以用<base href="">標(biāo)簽

      <base> 標(biāo)簽為頁面上的所有鏈接規(guī)定默認(rèn)地址或默認(rèn)目標(biāo)。通常情況下,瀏覽器會(huì)從當(dāng)前文檔的 URL 中提取相應(yīng)的元素來填寫相對(duì) URL 中的空白。

      jsp中先聲明schema://server:port/contextpath/

      <%
      String path = request.getContextPath();
      String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
      %>

      然后在頁面上聲明base標(biāo)簽,指定base的url

      <base href="<%=basePath%>">

      這樣的話頁面中所有的圖片或這里鏈接都會(huì)在schema://server:port/contextpath/下面找

       

        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶 評(píng)論公約

        類似文章 更多