首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

急项目中的图片无法显示,加10分!解决方法

2012-01-10 
急啊,项目中的图片无法显示,加10分!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!这个登陆页面啊,可以正常登陆,但是图

急啊,项目中的图片无法显示,加10分!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
这个登陆页面啊,可以正常登陆,但是图片去无法显示,我的程序代码如下!!!!!

weblogin.jsp代码以及所对应的程序界面!
<%@ page language="java" pageEncoding="GBK"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean"%> 
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%>
<html>
<head>
<title>用户登陆页面</title>
<link href="style1.css" rel="stylesheet" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<!-- ImageReady Slices (未标题-2) -->
<table id="__01" width="1003" height="604" border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<img src="images/login_01.jpg" width="252" height="175" alt=""></td>
<td>
<img src="images/login_02.jpg" width="519" height="175" alt=""></td>
<td>
<img src="images/login_03.jpg" width="232" height="175" alt=""></td>
</tr>
<tr>
<td>
<img src="images/login_04.jpg" width="252" height="323" alt=""></td>
<td>
<html:form action="/web.do">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
  <th height="35" colspan="2" scope="col">请输入用户名和口令</th>
  </tr>
  <tr>
  <td width="37%" height="35" align="right">userName:</td>
  <td width="76%">&nbsp;<html:text property="userName" style="width:50%"/><html:errors property="userName"/></td>
  </tr>
  <tr>
  <td height="35" align="right">userPassword:</td>
  <td>&nbsp;<html:text property="userPassword" style="width:50%"/><html:errors property="userPassword"/></td>
  </tr>
  <tr>
  <td height="35" colspan="2" align="center"><html:submit/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<html:cancel/></td>
  </tr>
  <tr>
  <td height="35" colspan="2" align="center"><br>
<br>
<br>
注:如果您不能正确登陆,请您联系系统管理员,或者<br><br>进入<a href="#">注册</a>页面注册,之后您才可以进入主界面查看您要看到的任何消息!</td>
  </tr>  
  </table>
</html:form>
</td>
<td>
<img src="images/login_06.jpg" width="232" height="323" alt=""></td>
</tr>
<tr>
<td>
<img src="images/login_07.jpg" width="252" height="106" alt=""></td>
<td>
<img src="images/login_08.jpg" width="519" height="106" alt=""></td>
<td>
<img src="images/login_09.jpg" width="232" height="106" alt=""></td>


</tr>
</table>
<!-- End ImageReady Slices -->
</body>
</html>
这是图片地址:

但是当我没有在userName的文本框,userPassword文本框中输入任何信息时却显示如下图片,请问是为什么?

weblogin.jsp中的图片转到web.do后就没有图片了,这是这儿,很郁闷,请知道的朋友告诉我怎么弄,当没有输入任何信息时转到web.do中能显示图片如登陆页面一样!!!!!

struts-config.xml数据为:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">

<struts-config>
  <data-sources />
  <form-beans >
  <form-bean name="webForm" type="com.yourcompany.struts.form.WebForm" />

  </form-beans>

  <global-exceptions />
  <global-forwards >
  <forward name="INDEX" path="/form/index.jsp" />
  </global-forwards>

  <action-mappings >
  <action
  attribute="webForm"
  input="/form/weblogin.jsp"
  name="webForm"
  path="/web"
  scope="request"
  type="com.yourcompany.struts.action.WebAction" />

  </action-mappings>

  <message-resources parameter="com.yourcompany.struts.ApplicationResources" />
</struts-config>

WebAction.java中的数据为:
package com.yourcompany.struts.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.yourcompany.struts.form.WebForm;

public class WebAction extends Action {

public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
WebForm webForm = (WebForm) form;// TODO Auto-generated method stub
String name = webForm.getUserName();
String password = webForm.getUserPassword();
if((name==null)||(name.length()<1)&&(password==null)||password.length()<1){

return mapping.findForward("WEBLOGIN");
}else{
request.setAttribute("userName", name);
request.setAttribute("userPassword", password);
return mapping.findForward("INDEX");
}
}
}
WebForm.java数据为:
package com.yourcompany.struts.form;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

public class WebForm extends ActionForm {

private String userName;

private String userPassword;

public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
if((userName==null)||(userName.length()<1)){
errors.add("userName", new ActionError("web.jsp.weblogin.userName"));
}
if((userPassword==null)||(userPassword.length()<1)){
errors.add("userPassword", new ActionError("web.jsp.weblogin.userPassword"));
}
return errors;
}

public void reset(ActionMapping mapping, HttpServletRequest request) {
this.userName=null;
this.userPassword=null;
}

public String getUserName() {
return userName;
}

public void setUserName(String userName) {
this.userName = userName;


}

public String getUserPassword() {
return userPassword;
}

public void setUserPassword(String userPassword) {
this.userPassword = userPassword;
}
}

请各位高手都进来看看,为什么????!



[解决办法]
在通过struts跳转之后是可能出现这种问题。你把图片的绝对路径写上就可以了!如:${pageContext.request.contextPath }/message/1.jpg

热点排行