一、
<s:a href="/emp_viewUpdate?id=%{#emp.id}">修改</s:a>
使用这个标签时,基础没学好,href路径前加了一个“/”,导致报错,总结,去掉“/”就行了,回顾:
- 绝对 URL - 指向另一个站点(比如 href="http://www.example.com/index.htm")
- 相对 URL - 指向站点内的某个文件(href="index.htm")
- 锚 URL - 指向页面中的锚(href="#top")
二、名称空间配置问题
警告: No configuration found for the specified action: '/emp_save' in namespace: '/'. Form action defaulting to 'action' attribute's literal value.
警告: No configuration found for the specified action: '/emp_update' in namespace: '/'. Form action defaulting to 'action' attribute's literal value.
Struts.xml
<package name="emp" extends = "struts-default" namespace = "/">
<global-results>
<result name = "error">/error.jsp</result>
</global-results>
<action name = "emp_*" class = "cn.itcast.action.EmployeeAcion" method = "{1}">
<result name = "list">/WEB-INF/list.jsp</result>
<!-- 进入修改页面 -->
<result name = "update">/WEB-INF/update.jsp</result>
</action>
</package>
struts表单
<s:form action="/emp_update" method="post" namespace="/">
<s:form action="/emp_save" method="post" namespace="/">
这样写的表单就会报上述两条警告,一下为正确写法:
<s:form action="emp_update" method="post" namespace="/">
<s:form action="emp_save" method="post" namespace="/">
指定了namespace为“/”,则
struts2
会直接在“/”命名空间寻找,在这个命名空间里找不到请求的
action“/emp_save”和“/emp_update”,只能再下一级的名称空间中才能找到指定的action,因此也会抛出一条类似的信息。