1.basePath方式 <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> 在url加入<%=basePath%>如:http://192.168.66.66:8089/x…
今天在jsp页面中引入jquery的时候因为路径不对总是报404,网上的方法找到几种试了试但是最后结果还是不生效,遂想起原先的项目中有引入外部jquery的例子,所以立马看了看,发现当时的项目中是用${pageContext.request.contextPath}来获得项目路径的.于是马上改成下面那样的方法. ${pageContext.request.contextPath}这个方法是获得项目绝对路径的方法 下面是我贴出我项目的结构和引入的代码 ,…
转自http://caodaoxi.iteye.com/blog/1234805     在jsp和class文件中调用的相对路径不同. 在jsp里,根目录是WebRoot 在class文件中,根目录是WebRoot/WEB-INF/classes 当然你也可以用System.getProperty("user.dir")获取你工程的绝对路径.            另:在Jsp,Servlet,Java中详细获得路径的方法!            1.jsp中取得路径:      …
废话不多说,直接上代码 <%@ page language="java" import="java.util.*" pageEncoding="GBK"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Server Info</title…
Calendar c = Calendar.getInstance(); int year = c.get(Calendar.YEAR); int month = c.get(Calendar.MONTH); int day= c.get(Calendar.DAY);   这三行加在<%   %>里面 调用时用<%= year  %><%= month%><%= day%>…
1.在JSF环境中获取到ServletContext: 1 2 ServletContext sc = (ServletContext)FacesContext.         getCurrentInstance().getExternalContext().getContext(); 2.servlet中获得项目绝对路径 1 2 String filePath=this.getServletConfig().         getServletContext().getRealPath(…
<%@ page language="java" pageEncoding="UTF-8"%><%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %><%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>&…
---恢复内容开始--- 自建目录中jsp页面访问servlet路径出错404 使用eclipse建立的项目,总是会遇到路径问题,比如jsp页面访问servlet,jsp在默认的路径.jsp在自建目录中的访问路径(web.xml的URL)是有区别的.若是访问路径设置不对,总会出现头痛的404访问不到结果: 下面是giveRadius.jsp页面输入半径,提交到servlet的Computer.java中求出面积. 一.jsp页面在默认的WebConnet下面 1 项目结构 2 web.xml内容…
  createTime--2016年10月12日16:20:02Author:Marydonjsp页面获取集合的长度 在jsp页面与js中不能通过${list.size}取列表长度,而是引入jstl标签库的fn标签 <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> ${fn:length(list)}获取 例子: alert('${fn:length(model…
jsp页面中的路径问题: 一般情况下,jsp中路径问题是和我们之前在servlet中讨论的html里面的路径问题是一 样的,但是在[jsp中可以动态获得该项目的url]. 如果在jsp页面的上面写了这样一个脚本: <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+ request.getServerName()+":"+request.g…