tomcat 发布应用程序后的问题 解决后另给100分

悬赏:10 发布时间:2008-07-25 提问人:nieliqiang84 (初级程序员)

我发布了一个项目  在 C:\Program Files\Tomcat 5.5\conf\server.xml 中的配置是这样的
<Service  name="Catalina">
    <Connector
        port="80"
        redirectPort="8443"
        minSpareThreads="25"
        connectionTimeout="20000"
        maxSpareThreads="75"
        maxThreads="150"
        maxHttpHeaderSize="8192">
    </Connector>
    <Connector
        port="8009"
        redirectPort="8443"
        protocol="AJP/1.3">
    </Connector>
   

  <Engine name="Catalina" defaultHost="w1.yingxin186.com">


  <Host name="w1.yingxin186.com" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false"  mlNamespaceAware="false"/>

  <Host name="www4.yingxin186.com" appBase="c://web" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
<Context  path=""  docBase="yingxinTD" workDir="yingxinTD" reloadable="true"/>
  </Host>

  <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false"/>

</Engine>
</Service>
这里对配置文件说明一下:

port="80" 采用80端口
工程放在 c://web 包中 工程名是 yingxinTD

我配置好后在地址栏中输入 www4.yingxin186.com 就可以访问我的工程了,可以进入工程的登录页面 (yingxinTD 是工程名)
当我输入用户名和密码之后,也可以进入Action中,我们登录不是要使用Session记录用户的状态吗?而我的Action中记录了Session后
它跳转到另一个页面,确取不到Session中的值,我我对比了两个页面它们的Session的Session ID ,结果 ID 是不一样的,

而且我又用 w1.yingxin186.com 登录tomcat服务器主页,输入了用户名和密码也进不了tomcat的管理页面

我不知道这是怎么回事
请各位帮帮忙,多少分我都给了~~ 不胜感激!

在内部网配置了两个NDS 即:w1.yingxin186.com 和 www4.yingxin186.com
问题补充:
我现在把一系列的代码贴出来吧:
好的我现在把一系列的代码贴出来。首先是登录页面,其中有验证码的,验证码是以网页形式生成了一张图片,而验证码页面中就定义了存储验证码数字

下面是验证码生成的JSP页面

<%!
Color getRandColor(int fc,int bc){//给定范围获得随机颜色
    Random random = new Random();
    if(fc>255) fc=255;
    if(bc>255) bc=255;
    int r=fc+random.nextInt(bc-fc);
    int g=fc+random.nextInt(bc-fc);
    int b=fc+random.nextInt(bc-fc);
    return new Color(r,g,b);
    }
%>
<%
//设置页面不缓存
response.setHeader("Pragma","No-cache");
response.setHeader("Cache-Control","no-cache");
response.setDateHeader("Expires", 0);

// 在内存中创建图象
int width=60, height=20;
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);

// 获取图形上下文
Graphics g = image.getGraphics();

//生成随机类
Random random = new Random();

// 设定背景色
g.setColor(getRandColor(200,250));
g.fillRect(0, 0, width, height);

//设定字体
g.setFont(new Font("Times New Roman",Font.PLAIN,18));

//画边框
//g.setColor(new Color());
//g.drawRect(0,0,width-1,height-1);

// 随机产生155条干扰线,使图象中的认证码不易被其它程序探测到
g.setColor(getRandColor(160,200));
for (int i=0;i <155;i++)
{
int x = random.nextInt(width);
int y = random.nextInt(height);
    int xl = random.nextInt(12);
    int yl = random.nextInt(12);
g.drawLine(x,y,x+xl,y+yl);
}

// 取随机产生的认证码(4位数字)
String sRand="";
for (int i=0;i <4;i++){
  String rand=String.valueOf(random.nextInt(10));
  sRand+=rand;
  // 将认证码显示到图象中
  g.setColor(new Color(20+random.nextInt(110),20+random.nextInt(110),20+random.nextInt(110)));
//调用函数出来的颜色相同,可能是因为种子太接近,所以只能直接生成
  g.drawString(rand,13*i+6,16);
}

// 将认证码存入SESSION
session.setAttribute("rand",sRand);
//session.setAttribute("myname","xiaoqiang");
// System.out.print("生成的验证码是:"+session.getAttribute("rand"));

System.out.println("session id 号是==》"+session.getId());  //我在这里打印出 当前页面里的SessionID

// 图象生效
g.dispose();

// 输出图象到页面
ImageIO.write(image, "JPEG", response.getOutputStream());
out.clear();
out = pageContext.pushBody();

%>


下面是登录页面的代码,一些啰嗦的代码我就省了

用户帐号: <html:text property="user_id"> </html:text>
用户密码: <html:password property="user_pwd"> </html:password>
验证码:   <input type="text"  id="rand" name="rand" value="" size="10">
  <img alt="" src="/yingxinTD/pages/show/image.jsp"/>  这里是验证码输出


之后提交到Action


String rand = (String)session.getAttribute("rand");//系统生成的验证码

String input = request.getParameter("rand"); //用户输入的验证码

System.out.println(session.getId()); ());  //我在这里打印出 当前的SessionID

现在发现 在Action 中的SessionID 和 验证码生成的JSP页面中的 SessionID 是不一样的 这样那么 (String)session.getAttribute("rand")
获取的验证码字段当然也就为 null 了。
以上这些问题只有在我发布的时候才会这样。
现在回到我关于使用 http://www4.yingxin186.com 来访问工程,如果用这种格式就会ID不同,但如果在这个格式的后面再加上工程名去访问就不会了即: http://www4.yingxin186.com/yingxinTD 这样访问就一切正常
而我要的确不是这样的效果,我想要用户输入 http://www4.yingxin186.com 这个就 能够正常访问,进行操作

采纳的答案

2008-08-06 zhai puhong (资深程序员)

楼主,你在tomcat 的 server.xml 的 Engine 或者 Host 元素配置一个DefaultContext 属性试试。http://www4.yingxin186.com 这个的appBase已经被你换到了c://web,这个目录下可以放很多Context,即部署很多应用。而<Host name="w1.yingxin186.com" appBase="webapps"……他的默认'DefaultContext' 为webapps/ROOT, 不知道我说的你明白没有,我这也没合适的环境来测试我刚说的,希望有用

提问者对于答案的评价:
谢谢你们

其他回答

====================
而我的Action中记录了Session后
它跳转到另一个页面
===================
跳转到什么页面?还是这个主机吗?如果不是同一个主机,当然不一样了。



www4.yingxin186.com这个主机Context path设置为"",跟tomcat的ROOT有可能有冲突。你换成别的试验一下,
sunsong (初级程序员) 2008-07-26