|  三、图片的显示 
 1.写一个显示图片的Action,代码结构如下: 
public class PhotoAction extends Action { 
  private static final String CONTENT_TYPE = "image/gif"; 
  public ActionForward perform(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) 
  throws ServletException, IOException{ 
    response.setContentType(CONTENT_TYPE); 
    ...//GET PARAM employeeId 
    ServletOutputStream out = response.getOutputStream(); 
    InputStream in =null; 
    try{ 
        in = ...//get blob pic 
    } 
     catch (Throwable e) { 
        e.printStackTrace(); 
     } 
   if(in!=null){ 
     try { 
       int len; 
       byte buf[] = new byte[4096]; 
       while ( (len = in.read(buf, 0, 4096)) != -1) { 
         out.write(buf, 0, len); 
       } 
     } 
     catch (IOException ioe) { 
       ioe.printStackTrace(); 
     } 
   } 
    return null; 
  } 
} 
2.在显示图片的jsp页面写如下代码: 
<html:img height="98%" alt="职工照片" src="photoAction.do" paramId="employeeId" paramName="ePhotoForm" paramProperty="employeeId" width="150" border="0" align="center" /> 
四、使ApplicationResources.properties支持中文显示: 
进入命令提示符页面,进入jdk安装路径下的bin目录,执行一下命令: 
native2ascII - encoding gb2312 ApplicationResources_ISO.properties(原文件) AllicationResources.properties(新生成文件) 
即可在jsp页面显示中文。 
但是,目前还有一点问题没解决,就是在jsp页面显示的内容为“null error ”,你出现过相同问题吗?怎么解决的? 
五:Action中的文件路径问题: 
在Action中需要调用一个xml文件,是用相对路径在本地编译没有问题,但是一放在服务器上执行就找不到文件路径。找了很多解决方法,最后调用了request.getRealPath("/")方法,行的通,但是这个方法已经不被建议使用了。你有更好的方法吗? 
六:jsp页面显示字符串数组: 
<logic:iterate name="dateList" id="dateList" type="java.lang.String"> 
<bean:write name="dateList"> 
</logic:iterate> 
七:如何定义自己的jsp文件发布路径(windows2000环境下实践通过): 
打开tomcat目录下conf文件夹下的server.xml文件,找到<!-Tomcat manager Context->标签 
在其<context >标签后,添加自己的发布路径,如下: 
<context path="/mywebapps" docbase="D:/work" debug="0" reloadable="true"/> 
重启tomcat,访问:/localhost:8080/mybwebapps/,ok! 
八:如何解决偏僻难字的显示问题: 
使用大字符集,将所有jsp页面字符集设置如下:<%@ page contentType="text/html;charset=GBK" %>注意:GBK一定得大写。 
九:页面刷新数据重复提交问题: 
解决的方法就是采用重定向。与二的解决方法相同: 
    1.将struts-config.xml中redirect属性置为true。 
    2.如果是带参数的跳转: 
    ActionForward forward = mapping.findForward("success"); 
    StringBuffer bf = new StringBuffer(forward.getPath()); 
    bf.append("?id=1");//参数 
    return new ActionForward(bf.toString(),true);  
十:其他: 
编程规范建议: 
数据库接口类命名:*DAO.JAVA 
逻辑类命名:*BO.JAVA 
ACTION命名:*Action.JAVA 
ACTIONFORM命名:*Form.JAVA 
然后一个功能模块的文件放在一个包内。  
都是一些比较初级的问题,但是希望能够助你在学习struts之初少走点弯路,也希望对于文中的问题给予指点,:)。 
   
 
  |