日期:2014-05-18  浏览次数:20810 次

struts怪异问题
web.xml
<?xml   version= "1.0 "   encoding= "UTF-8 "?>
<web-app>

<display-name> Struts   Hibernate   Spring </display-name>

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

<servlet>
<servlet-name> action </servlet-name>
<servlet-class> org.apache.struts.action.ActionServlet </servlet-class>
<init-param>
<param-name> config </param-name>
<param-value> /WEB-INF/struts-config.xml </param-value>
</init-param>
</servlet>

<servlet-mapping>
<servlet-name> action </servlet-name>
<url-pattern> *.do </url-pattern>
</servlet-mapping>

<taglib>      
<taglib-uri> /WEB-INF/struts-bean.tld </taglib-uri>      
<taglib-location> /WEB-INF/struts-bean.tld </taglib-location>      
</taglib>

<taglib>
<taglib-uri> /WEB-INF/struts-html.tld </taglib-uri>
<taglib-location> /WEB-INF/struts-html.tld </taglib-location>
</taglib>

<taglib>
<taglib-uri> /WEB-INF/struts-logic.tld </taglib-uri>
<taglib-location> /WEB-INF/struts-logic.tld </taglib-location>
</taglib>

<taglib>
<taglib-uri> /WEB-INF/struts-template.tld </taglib-uri>
<taglib-location> /WEB-INF/struts-template.tld </taglib-location>
</taglib>

</web-app>

struts-config.xml
<?xml   version= "1.0 "   encoding= "UTF-8 "?>
<struts-config>

<action-mappings>

<action   path= "/HelloWorld "
type= "hello.HelloAction "
name= "HelloForm "
scope= "request "
input= "index.jsp ">
<forward   name= "SayHello "   path= "index.jsp "/>
</action>

</action-mappings>

<form-beans>
<form-bean   name= "HelloForm "   type= "hello.HelloForm "/>
</form-beans>

<message-resources   parameter= "hello.app "/>

</struts-config>

HelloAction.java
package   hello;

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;

public   class   HelloAction   extends   Action   {

public   ActionForward   execute(ActionMapping   mapping,
ActionForm   form,
HttpServletRequest   request,
HttpServletResponse   response)   {

String   hf   =   (String)((HelloForm)form).getUserName();

request.setAttribute( "username ",   hf);

return   mapping.findForward( "SayHello ");
}
}

HelloForm.java
package   hello;