web.xml与struts-config.xml路径问题

day_moon 2015-11-10 08:45:20
1、product.jsp文件部分代码(可以只看红色部分):

function del() {
var id= document.getElementsByName("id");
if(checkCheckboxIsSelected(id,"请选择要删除的商品!")){
if(window.confirm('确定要删除么?')==true){
document.getElementById("fom").action = "<%=request.getContextPath()%>/product.do?method=delProduct";
document.getElementById("fom").submit();
}
}
}

2、web.xml文件:
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
</servlet>

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

3、struts-config.xml文件:
<action-mappings>
<action name="uploadForm" path="/product" type="com.example.redbaby.action.ProductAction" parameter="method" scope="request">
<forward name="toList" path="/jsp/product_list.jsp"/>
<forward name="toListAction" path="/product.do?method=toList" redirect="true"/>
<forward name="toEdit" path="/jsp/product_edit.jsp"/>
</action>
</action-mappings>

跪求各位大婶!
问题:1、"<%=request.getContextPath()%>/product.do?method=delProduct";访问的路径详细的过程是怎么样的呢?
为什么不是这样的呢?
2、为什么这样能访问到ProductAction类里面呢?
...全文
75 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
街头小贩 2015-11-15
  • 打赏
  • 举报
回复
访问的路径详细的过程是怎么样的呢 re: 1.第一步是访问web.xml查找路径定义,发现*.do由org.apache.struts.action.ActionServlet,处理 2.调用struts的配置文件查找映射定义 你怎么证明不是你画的哪样 为什么这样能访问到ProductAction类里面呢 re: 因为你调用的是/product.do,而 struts的配置的路径/product指向com.example.redbaby.action.ProductAction 你是没学过servlet吗?还是没搞明白struts

10,606

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 其他
社区管理员
  • 其他
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧