论坛首页 Java企业应用论坛

『提问』struts 验证失败,转发的时候,出现url错误?

浏览 3923 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2006-08-26  
软件环境:
struts 1.2 ,tomcat 5.0,jdk1.4
一个简单的登陆页面

验证,出错之后,返回到登陆页面
配置文件:
struts-config.xml 片段

  <form-beans>
    <form-bean name="registerForm" type="com.h819.struts.form.RegisterForm" />


  </form-beans>
  <action-mappings>
    <action
      attribute="registerForm"
      input="/user/register.jsp"
      name="registerForm"
      path="/register"
      type="com.h819.struts.action.RegisterAction"
      />


register.jsp

<%@ taglib uri="/WEB-INF/struts-nested.tld" prefix="nested" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ page contentType="text/html; charset=gb2312" language="java"
import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<style>
<!--a:hover{color:#000080; text-decoration:underline; }-->

<!--a{text-decoration:none}; //-->
</style>
<title>管理系统</title>

<link href="../../css/css.css" rel="stylesheet" type="text/css" />
</head>
<body  leftmargin="0" topmargin="0">
<div align="center">
  <center>
    <table border="0" cellpadding="0" bgcolor="white" cellspacing="0"
bordercolor="#111111" width="780"  height="100%">
      <tr>
        <td width="100%" height="117"><table border="0" cellpadding="0"
cellspacing="0"  bordercolor="#111111" width="100%"  height="117">
            <tr>
              <td background="../../images/top1a.jpg"><img border="0"
src="../../images/top1b.jpg" width="614" height="117" /></td>
            </tr>
          </table></td>
      </tr>
      <tr>
        <td width="100%"><table border="0" cellpadding="0" cellspacing="0"
bordercolor="#111111" width="780"  height="100%">
            <tr>
              <td width="166" valign="top"
background="../../images/menubakc.jpg">&</td>
              <td width="614" valign="top"><html:errors/>
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td><div align="center">
                        <html:form action="register.do" method="post"> <br />
                          <table width="100%" border="0" cellspacing="0"
cellpadding="0">
                            <tr>
                              <td><div align="center" class="title">用户注册
</div></td>
                            </tr>
                          </table>
                          <br />
                          <table width="291" border="0" cellpadding="0"
cellspacing="1" bgcolor="#336699">
                            <tr>
                              <td width="56" bgcolor="#FFFFFF"><div
align="left">登录名</div></td>
                              <td width="142" bgcolor="#FFFFFF"><div
align="left">
                                  <html:text maxlength="20"
property="loginname" size="20" />
                                </div></td>
                              <td width="89" bgcolor="#FFFFFF"><span
class="STYLE1">*</span></td>
                            </tr>
                            <tr>
                              <td bgcolor="#FFFFFF"><div align="center">
                                  <html:submit value="提交" property="Submit"/>
                                </div></td>
                              <td bgcolor="#FFFFFF"><div align="center">
                                  <html:reset value="重置"/>
                                </div></td>
                              <td bgcolor="#FFFFFF">&</td>
                            </tr>
                          </table>
                        </html:form>
                      </div></td>
                  </tr>
                </table></td>
            </tr>
          </table></td>
      </tr>
    </table>
  </center>
</div>
</body>
</html>

错误提示信息:
不能正确显示
你的分析:
在 registeForm 里面,简单验证,返回 errors, 直接返回到 登陆页面 register.jsp

问题是:

部署到tomcat 的webapp/test/user/register.jsp 下面
//test 为一个具体的应用

启动tomcat,可以访问用 http://localhost:8080/test/user/register.jsp
正常显示

故意输入错误,在 registerForm 中验证,返回到 register.jsp,可用正确返回到
register.jsp,并打印出错信息(说明配置文件和 registerForm 都是没有问题的,这个不
要怀疑了)

但返回的页面不能正常显示,原来的链接资源都不可用,
如register.jsp 中的图片a.gif 在 test/images/a.gif

**************** 问题

在第一次登陆的时候,能正常显示,链接是 http://localhost:8080/test/images/a.gif
出错返回的时候,却是 http://localhost:8080/images/a.gif


其他的链接资源都是这样,没有 test这个应用的名字
***************

即:出错跳转到原来的页面之后,所有的链接资源都没有了 test ?

如果把应用直接部署到 webapp 的根目录下面,就没有任何问题了

tomcat or struts 为什么记不住上下文 test 应用的名字?
有个同学用 weblogic 就没有这个问题

请问,大家遇到了么,是怎么解决的,还是我哪里配置有问题.

在一个tomcat下面部署多个应用,也比较常见呀.
   发表时间:2006-08-26  
翻了一下老帖,知道了原因

http://forum.iteye.com/viewtopic.php?p=133676
0 请登录后投票
   发表时间:2006-10-09  
解决这类URL错误的问题 你可以尝试以下两种方法
一、外部链接的地方使用标签
           <html:rewrite page="/images/a.gif"/>
这样你的action转向之后就不会出现URL错误的问题了
二、使用<html:base/>这个标签 具体用法去参照struts一些文档
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics