关于config这个对象应用问题!
这个是JSP应用开发详解(第二版)中的一个例子!
config.jsp页面内容如下:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<% int org=0;
int count=0;
try
{
org=Integer.parseInt(config.getInitParameter("counter"));
}
catch(Exception e)
{
out.println("org:"+e);
}
try
{
count=Integer.parseInt((application.getAttribute("config_counter").toString()));
}
catch(Exception e)
{
out.println("config_counter"+e);
}
if(count<org)count=org;
out.println("此页面已经访问了"+count+"次");
count++;
application.setAttribute("config_counter",new Integer(count));
%>
</body>
</html>
web中的内容如下:
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app 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 web-app_2_4.xsd"
version="2.4">
<display-name>Welcome to Tomcat</display-name>
<description>
study jsp
</description>
<servlet>
<servlet-name>
config_counter
</servlet-name>
<jsp-file>
/config.jsp
</jsp-file>
<init-param>
<param-name>
counter
</param-name>
<param-value>
1000
</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>config_counter</servlet-name>
<url-pattern>/config_counter</url-pattern>
</servlet-mapping>
</web-app>
这个config.jsp和web我是放在webapps\ROOT\ch4里面.
按课本中说的我用http://127.0.0.1:8080/ch4/config_counter访问可是提示如下:
type Status report
message /ch4/config_counter
description The requested resource (/ch4/config_counter) is not available.
我不知道我放错在哪里了,还有为什么要用config_counter访问而直接用config.jsp访问。
请帮小弟解答一下吧(在线等!!)