易截截图软件、单文件、免安装、纯绿色、仅160KB

servlet、jsp中获得项目绝对路径

servlet中获得项目绝对路径
String filePath=this.getServletConfig().getServletContext().getRealPath("/");
根目录所对应的绝对路径:request.getServletPath();
文件的绝对路径 :request.getSession().getServletContext().getRealPath(request.getRequestURI())
当前web应用的绝对路径 :servletConfig.getServletContext().getRealPath("/");
ServletContext对象获得几种方式:
Javax.servlet.http.HttpSession.getServletContext()
Javax.servlet.jsp.PageContext.getServletContext()
Javax.servlet.ServletConfig.getServletContext()
文件的绝对路径 :request.getSession().getServletContext().getRealPath(request.getRequestURI())
当前web应用的绝对路径 :servletConfig.getServletContext().getRealPath("/");


相关文档:

jsp 跳转方式

使用JSP大约有下列三种跳转方式:
1. response.sendRedirect();
2. response.setHeader("Location","");
3. <jsp:forward page="" />
经过试验得到下面的一些规则:
一. response.sendRedirect()
此语句前不允许有out.flush(),如果有out.flush(),会有异常:
java.lang.IllegalStateException: Can't send ......

在jsp页面间传递参数

(1)直接在URL请求后添加
   如:<a href="thexuan.jsp?action=transparams&detail=directe")直接传递参数/a> 
   特别的在使用response.sendRedirect做页面转向的时候,也可以用如下代码:
   response.sendRedirect("thexuan.jsp?action=transparams&de ......

jsp页面放到WEB INF 跟webroot的区别

JSP存放在 WEB-INF 跟webroot的区别
    放在webroot下面:优点,程序结构清晰,便于编码和维护;缺点,要加过滤器。
放在web-inf下面:优点,不用过滤器;缺点,打乱了程序结构,编码和维护麻烦点。
    webroot其实是一个名字而已,在部署后是看不到的,访问的时候在url里肯定也是 ......

jsp连接MySQL数据库 2

●jsp连接MySQL数据库
testmysql.jsp如下:
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<html>
<body>
<%Class.forName("org.gjt.mm.mysql.Driver").newInstance();
String url ="jdbc:mysql://localhost/softforum?
user=soft&pas ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号