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

用struts干的基于web的小程序页面显示空白

2011-12-06 
用struts做的基于web的小程序页面显示空白!代码如下:web.xml?xmlversion 1.0 encoding UTF-8 ?!D

用struts做的基于web的小程序页面显示空白!
代码如下:
web.xml

<?xml   version= "1.0 "   encoding= "UTF-8 "?>
<!DOCTYPE   web-app   PUBLIC   "-//Sun   Microsystems,   Inc.//DTD   Web   Application   2.3//EN "   "http://java.sun.com/dtd/web-app_2_3.dtd ">
<web-app>

<display-name> test </display-name>
<listener>
<listener-class> com.common.TimerListener </listener-class>
</listener>

<filter>
<filter-name> EncodingFilter </filter-name>
<display-name> EncodingFilter </display-name>
<filter-class> com.common.EncodingFilter </filter-class>
<init-param>
<param-name> encoding </param-name>
<param-value> UTF-8 </param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name> EncodingFilter </filter-name>
<url-pattern> /* </url-pattern>
</filter-mapping>


<servlet>
<servlet-name> action </servlet-name>
<servlet-class> org.apache.struts.action.ActionServlet </servlet-class>
<init-param>
<param-name> debug </param-name>
<param-value> 2 </param-value>
</init-param>
<init-param>
<param-name> config </param-name>
<param-value> /WEB-INF/struts-config.xml </param-value>
</init-param>
<load-on-startup> 2 </load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name> action </servlet-name>
<url-pattern> *.do </url-pattern>
</servlet-mapping>

<session-config>
<session-timeout> 60 </session-timeout>
</session-config>

<welcome-file-list>
<welcome-file> /jsp/main.jsp </welcome-file>
</welcome-file-list>

<taglib>
<taglib-uri> /tags/struts-bean </taglib-uri>
<taglib-location> /WEB-INF/tld/struts-bean.tld </taglib-location>
</taglib>
<taglib>
<taglib-uri> /tags/struts-html </taglib-uri>
<taglib-location> /WEB-INF/tld/struts-html.tld </taglib-location>
</taglib>
<taglib>
<taglib-uri> /tags/struts-logic </taglib-uri>
<taglib-location> /WEB-INF/tld/struts-logic.tld </taglib-location>
</taglib>
<taglib>
<taglib-uri> /tags/struts-nested </taglib-uri>
<taglib-location> /WEB-INF/tld/struts-nested.tld </taglib-location>
</taglib>
<taglib>
<taglib-uri> /tags/struts-tiles </taglib-uri>
<taglib-location> /WEB-INF/tld/struts-tiles.tld </taglib-location>
</taglib>
</web-app>

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_2.dtd ">
<struts-config>
<form-beans>
<form-bean   name= "fileUploadForm "   type= "com.form.FileUploadForm "/>
</form-beans>

<global-forwards>


<forward   name= "SUCCESS_KEY "   path= "/jsp/main.jsp "/>
        </global-forwards>
       
<action-mappings>

<action   name= "fileUploadForm "   path= "/main "   scope= "request "     type= "com.action.FileUploadAction "   input= "/jsp/main.jsp "   validate= "false ">
<forward   name= "SUCCESS "   path= "/jsp/main.jsp "/>
</action>
</action-mappings>
<message-resources   key= "cnM "   parameter= "label_zh_CN "/>
<message-resources     parameter= "label "/>
</struts-config>

action文件如下:
package   com.action;

import   java.io.OutputStream;

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   org.apache.struts.util.MessageResources;

import   com.bean.FileUploadBean;
import   com.common.Constants;;
/**
  *   @author   user
  *
  *   TODO   要更改此生成的类型注释的模板,请转至
  *   窗口   -   首选项   -   Java   -   代码样式   -   代码模板
  */
public   class   FileUploadAction   extends   Action{

public   ActionForward   execute(ActionMapping   mapping,ActionForm   actionform,
HttpServletRequest   request,   HttpServletResponse   response,   MessageResources   res)
throws   Exception   {
response.setContentType( "charset=UTF-8 ");
String   clg= "cnM ";
request.getSession().setAttribute( "LDIFF ",   clg);
String   s= " ";

FileUploadBean   up=new   FileUploadBean();
OutputStream   out   =   null;  
up.doUpload(request);    
s=res.getMessage( "lable.wenjianming ")+up.getFilename()+ "\n "+
res.getMessage( "lable.leixing ")   +   up.getContentType()+ "\n "+
res.getMessage( "lable.zuozhe ")   +   up.getContentType()+ "\n "+
res.getMessage( "lable.gongsi ")   +   up.getContentType()+ "\n "+
res.getMessage( "lable.shuoming ")   +   up.getContentType();

out.write(s.getBytes( "UTF-8 "));
out.flush();
        out.close();
return   mapping.findForward(Constants.SUCCESS_KEY);
}
}

jsp文件如下:
<%@   page   contentType= "text/html;   charset=UTF-8 "   language= "java "%>
<%@   taglib   uri= "/tags/struts-html "   prefix= "html "   %>
<%@   taglib   uri= "/tags/struts-bean "   prefix= "bean "   %>
<%@   taglib   uri= "/tags/struts-logic "   prefix= "logic "   %>
<%
String   lg   =   (String)session.getAttribute( "LDIFF ");
%>
<html:html>    
<head>  
<title> <bean:message   bundle= ' <%=lg%> '   key= "lable.shangzai "/> </title>  


</head>  
<body>  
<html:form   action= "main.do "   method= "post ">
<bean:message   bundle= ' <%=lg%> '   key= "lable.zuozhe "/> <input   type=text   name=author>  
<br>  
<bean:message   bundle= ' <%=lg%> '   key= "lable.gongsi "/> <input   type=text   name=company>  
<br>  
<bean:message   bundle= ' <%=lg%> '   key= "lable.shuoming "/> <textarea   name=comment> </textarea>  
<br>  
<bean:message   bundle= ' <%=lg%> '   key= "lable.xuanze "/> <input   type=file   name=filename>  
<br>  
<bean:message   bundle= ' <%=lg%> '   key= "lable.miaoshu "/> <input   type=text   name=description>  
<br>  
<input   type=submit   value= "Upload ">  
</html:form>
</body>  
</html:html>  

如果单纯的运行jsp页面,可以显示页面
如果运行.do文件,就会显示空白页面
所有的可能出现的问题都考虑了,还是不行,请高手指教
不胜感激!

[解决办法]
路径(jsp 和 javaSource的)都正确?

热点排行