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

页面不会跳转
我读取displayAddProductForm.jsp页面后输入几个参数,目的是要跳转到displaySaveProduct.jsp那里显示出我输入的参数,但就是不会跳转,情问问题在哪

我的jsp页面displayAddProductForm.jsp如下:

<form method="post" action="?action=saveProduct">
<table>
<tr>
<td>product name:</td><td><input type="text" name="productName" /></td>
</tr>

<tr>
<td>Description:</td><td><input type="text" name="description" /></td>
</tr>

<tr>
<td>Price:</td><td><input type="text" name="price" /></td>
</tr>

<tr>
<td><input type="reset"/></td><td><input type="submit" value="add"/></td>
</tr>
</table>
</form>

在WEB-INF/classes/app01a下的SaveProductAction代码如下:package app01a;
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 SaveProductAction extends Action 
{
  public ActionForward execute(ActionMapping mappings,ActionForm form,HttpServletRequest req,HttpServletResponse resp)
throws Exception
{
ProductTO product=new ProductTO();
product.setProductName(req.getParameter("productName"));
product.setDescription(req.getParameter("description"));
product.setPrice(req.getParameter("price"));
req.setAttribute("product", product);
return mappings.findForward("success");
}
}

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>struts</display-name>
  <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>
<load-on-startup>1</load-on-startup>
  </servlet>
  
  <servlet-mapping>
  <servlet-name>action</servlet-name>
  <url-pattern>*.do</url-pattern>
  </servlet-mapping>
</web-app>

struts-config.xml如下:<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE struts-config SYSTEM 
"http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd">

<struts-config>
  <action-mappings>
  <action path="/displayAddProductForm" forward="/displayAddProductForm.jsp"/>
  <action path="/saveProduct" scope="page" type="app01a.SaveProductAction"> 
<forward name="success" path="/displaySaveProduct.jsp"/>
  </action>
  </action-mappings>
</struts-config>






------解决方案--------------------
<form method="post" action="?action=saveProduct"> 应该是这里的问题吧? 你在<action-mappings> 里配的是path="/saveProduct".