这是工程图:war包:结果图(html):结果图(jsp):]index.html代码:
<!DOCTYPE html PUBLIC "-//W3C//DT D HIML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; Charset=GB2312">
<title>首都经济贸易大学搜索引擎</title>
</head>
<body>
.. ...
<div id="search" align="center">
... ...
<form action="s.jsp" method="GET">
<input type="text" name="keys" size=36 class=kw maxlength="100" >&nbsp;&nbsp;
<input type="submit" value="搜索 "class=sb>
... ...
</form>
......
</div>
</body>
</html>
s.jsp代码
<%@ page language="java" pageEncoding="GB2312"%>
<jsp:directive.page import="java.lang.Integer"/>
<jsp:directive.page import="cn.edu.cueb.search.util.*"/>
<!DOCTYPE html PUBLIC "-//W3C//DID HTML 4.01 Transitional//EN" >
<html>
<head>
<title>首都经济贸易大学搜索引擎</title>
</head>
<body>
......
<div id="inf" class="inf" style="visibility:visible">Loading...</div>
<div class="inf">
<%
String param=request.getParameter("keys");
param=new String(param.getBytes("iso-8859-1"),"gb2312");
out.print("您提交的关键字 :"+param);
%></div>
<div>查找结果</div>
<div id="result" class="result" style="visibility:hidden">
<%
String keys=CharacterHandle.trans(param);
String[] results=new Query().getQueryResult(keys.split(" "));
int length=results.length;
int start=1;
int end=0;
if(request.getParameter("page")!=null){
start=Integer.parseInt(request.getParameter("page"));
}
//计算页数与序号的对应关系
start=(start-1)*10;
end=start+10;
if(end>=length){
end=length;
}
for(int i=start;i<end;i++){
int position=results[i].indexOf("|");
String title=results[i].substring(0,position);
position=results[i].indexOf("mirror");
String url=results[i].substring(position+7,results[i].indexOf("|",position+1));
position=results[i].indexOf("|",position+1);
String context=results[i].substring(position+1);
context=context.replace(" ","");
context=context.replace("&nbsp;"," ");
String summary="";
String[] k=keys.split(" ");
int maxChar=100;
int l=k.length;
int summaryStart=0;
int summaryEnd=0;
if(l==1){
summaryStart=context.indexOf(k[0])+k[0].length();
summaryEnd=summaryStart+maxChar;
if(summaryEnd>context.length()){
summaryEnd=context.length();
}
summary=context.substring(summaryStart,summaryEnd);
summary="<font color=\"#FF0000\">"+k[0]+"</font>"+summary;
}
else{
int count=maxChar/1;
if(count<5){
count=5;
}
for(int j=0;j<1;j++){
summaryStart=context.indexOf(k[j])+k[0].length();
summaryEnd=summaryStart+count;
if(summaryEnd>context.length()){
summaryEnd=context.length();
}
if("".equals(summary)){
summary="<font color=\"#FF0000\">"+k[0]+"</font>"+context.substring(summaryStart,summaryEnd);
}
}
}
out.print("<a href=\"http://"+url+"\">"+"<font color=\"#0033cc\">"+title+"</a>"+"</font><br/>");
out.print("<font color=\008000\">"+summary+"<a href=\"http://"+url+"\">"+"<font color=\"#0033cc\">more</a>"+"</foot>...</font><br />");
}
%>
</div>
<div id="page">
<%
for(int j=0;j<=length;j=j+10)
out.print("<a href=\"s.jsp?keys="+keys+"&page="+(j/10+1)+"\">["+(j/10+1)+"]</a>&nbsp;");
%>
</div>
<%---显示结果---%>
<script type="text/javascript">
document.getElementByld("inf").style.visibility="hidden";
document.getElementByld("result").style.visibility="visible";
</script>
</body>
</html>

解决方案 »

  1.   

    WEB-INF是Java的WEB应用的安全目录,客户端无法访问,只有服务端可以访问的目录。
    如果想在页面中直接访问其中的文件,可以通过服务端跳转访问。
    重定向。自己百度如何访问web-INF下的资源,很多资料。
      

  2.   

    把s.jsp放在 webcontent的根目录下面,或者在webcontent下创建一个index.jsp 去请求 s.jsp .通过url是无法访问到web-inf下面的内容的
      

  3.   

    在web.xml中加上<welcome-file>/WEB-INF/s.jsp</welcome-file>且放在第一行就不会出错了 你的index.html能展示也是因为这个配置 配置过以后,只能出现这两者中的一个 因为这个是顺序寻找的 找到了就不会继续展示了 这也能理解 默认页肯定是一个如果你两个都想看到的话 那就在s.jsp中加入<meta http-equiv="Refresh" content="5; URL=/index.jsp"> 5秒后会跳转的
    但前提是两个页面至少有一个是在WEB-INF之外的 因为refresh是更改地址的 是客户端请求 客户端请去是无法访问web-inf文件夹下的东西的