<%@ page language="java" contentType="text/html;charset=GBK" %>
<html>
<head>
<title>hello page</title>
</head>
<body>
<center>
<h1> <font size="30" color="red"> hello,welcome to visit this page....</font> </h1>
</center>
<%=application.getInitParameter("name") %><hr><br>
<%=application.getInitParameter("age") %><hr><br>
</body>
</html>
我的WEB-INF文件夹下的web.xml配置文件已经配置号了如下:<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">    <context-param>
    <param-name>name</param-name>
    <param-value>haodu</param-value>
    </context-param>
    <context-param>
    <param-name>age</param-name>
    <param-value>25<param-value>   
   </context-param>
</web-app>
是在jsp文件中为什么用application内置对象却读不出name和age参数值?
麻烦大家帮忙解决下,谢谢!web.xmlJava

解决方案 »

  1.   

    改为this.getServletContext().getInitParameter("name")看看
      

  2.   


    另外,也穷举下看看有啥:
    Enumeration  enema = application.getInitParameterNames();
    while(enema.hasMoreElements()){
      String name=(String)enema.nextElement();
      String value=application.getInitParameter(name);
      System.out.println(name + "= " + value);
    }避免是配置没有生效。
      

  3.   

    谢谢楼上两位,我试了但是还是不行啊?我想问下,我的项目是部署在webapps/ROOT下这样是对的吧?不会是这个原因出错的吧?但是我部署在webapps下面运行说找不到服务器啊,我运行http://localhost:8080是自动运行webspps/ROOT/目录下的index.jsp文件啊?
      

  4.   

    部署在root下就不要项目名了,直接复制webroot下的东西到root。
      

  5.   

    但是我部署到webapps下面输入http://localhost:8080/myWebDemo/却说没有该资源啊,请问这怎么部署啊?
      

  6.   

    有没有自己去tomcat下的webapp文件夹内看看有没有就行了。
      

  7.   

    可是这个路径本来就有问题,因为运行http://localhost:8080/本身默认的运行路径就是webapps/ROOT/index.jsp而我的项目放在webapps下面怎么找得到资源?
      

  8.   

    我的项目是部署在webapps/ROOT下这样是对的吧?不会是这个原因出错的吧?错的,要么你放在webapp下,要么你把你的项目的所有资源粘贴到root中,不要套一个文件夹再往root下放。