Java代码
<html:form action="/userAction/showUserList.do">
<html:submit>显示所有用户</html:submit>
</html:form> <html:form action="/userAction/showUserList.do">
<html:submit>显示所有用户</html:submit>
</html:form>上面是我的提交
下面是struts配置
Java代码
<action path="/userAction/showUserList"
type="usermodule.UserAction"
name="userForm"
parameter="showUserList"
scope="request"
input="/root/user/userlist.jsp">
<forward name="success" path="/root/user/userlist.jsp"></forward>
</action> 然后点击显示所有用户后有没输出信息
下面是jsp页面
Java代码
<table>
<tr>
<td>登陆名 </td>
<td>真实姓名 </td>
<td>EMAIL</td>
</tr>
<logic:present name="userList">
<logic:iterate id="UserForm" name="userList" type="usermodule.DBUser">
<tr>
<td>
<bean:write name="UserForm" property="username"/>
</td>
<td>
<bean:write name="UserForm" property="realname"/>
</td>
<td>
<bean:write name="UserForm" property="email"/>
</td>
</tr>
</logic:iterate>
</logic:present>
<tr><td>
<html:form action="/userAction/showUserList.do">
<html:submit>显示所有用户</html:submit>
</html:form>
</td></tr>
</table> <table>
<tr>
<td>登陆名 </td>
<td>真实姓名 </td>
<td>EMAIL</td>
</tr>
<logic:present name="userList">
<logic:iterate id="UserForm" name="userList" type="usermodule.DBUser">
<tr>
<td>
<bean:write name="UserForm" property="username"/>
</td>
<td>
<bean:write name="UserForm" property="realname"/>
</td>
<td>
<bean:write name="UserForm" property="email"/>
</td>
</tr>
</logic:iterate>
</logic:present>
<tr><td>
<html:form action="/userAction/showUserList.do">
<html:submit>显示所有用户</html:submit>
</html:form>
</td></tr>
</table>我在action中设置了断点,调试时发现根本就没有进入到action类不明白啊,又没有显示错误
<html:form action="/userAction/showUserList.do">
<html:submit>显示所有用户</html:submit>
</html:form> <html:form action="/userAction/showUserList.do">
<html:submit>显示所有用户</html:submit>
</html:form>上面是我的提交
下面是struts配置
Java代码
<action path="/userAction/showUserList"
type="usermodule.UserAction"
name="userForm"
parameter="showUserList"
scope="request"
input="/root/user/userlist.jsp">
<forward name="success" path="/root/user/userlist.jsp"></forward>
</action> 然后点击显示所有用户后有没输出信息
下面是jsp页面
Java代码
<table>
<tr>
<td>登陆名 </td>
<td>真实姓名 </td>
<td>EMAIL</td>
</tr>
<logic:present name="userList">
<logic:iterate id="UserForm" name="userList" type="usermodule.DBUser">
<tr>
<td>
<bean:write name="UserForm" property="username"/>
</td>
<td>
<bean:write name="UserForm" property="realname"/>
</td>
<td>
<bean:write name="UserForm" property="email"/>
</td>
</tr>
</logic:iterate>
</logic:present>
<tr><td>
<html:form action="/userAction/showUserList.do">
<html:submit>显示所有用户</html:submit>
</html:form>
</td></tr>
</table> <table>
<tr>
<td>登陆名 </td>
<td>真实姓名 </td>
<td>EMAIL</td>
</tr>
<logic:present name="userList">
<logic:iterate id="UserForm" name="userList" type="usermodule.DBUser">
<tr>
<td>
<bean:write name="UserForm" property="username"/>
</td>
<td>
<bean:write name="UserForm" property="realname"/>
</td>
<td>
<bean:write name="UserForm" property="email"/>
</td>
</tr>
</logic:iterate>
</logic:present>
<tr><td>
<html:form action="/userAction/showUserList.do">
<html:submit>显示所有用户</html:submit>
</html:form>
</td></tr>
</table>我在action中设置了断点,调试时发现根本就没有进入到action类不明白啊,又没有显示错误
解决方案 »
- 我在VM VirtualBox里安装的linux系统密码忘记了,该怎么办呢?
- 关于Struts标签无法解析的问题
- 如何在一个项目中 如何 调用另外一个项目中的方法
- 急急急!在spring2.5+hibernate3.2+Struts2.0中配置c3p0连接池报错,
- [Web 打印] 关于如何控制客户端打印机设置的经验交流
- 请问怎样在hirbernate中调用Oracle存储过程?
- 问一个SQL查询的问题,有点拗口
- 为什么我在 创建PreparedStatement 对象时总是把Tomcat 搞死?????
- 请问jsp用到的bean如何注册,我用的是tomcat......
- 怎样让Frame类创建的窗口的最大化按钮失效?
- 用struts +hibernate 用一个action查询一个表出错,求解
- js 中可不可以用struts2 标签
你的struts-config.xml中配置了 parameter
你是不是用了DispatchAction。
public ActionForward execute(ActionMapping mapping,
ActionForm form, HttpServletRequest request, HttpServletResponse response)
{
String myaction = mapping.getParameter();
if(myaction.equalsIgnoreCase("addUser"))
{
return createUserAction(mapping,form,request,response);
}
else if(myaction.equalsIgnoreCase("updateUser"))
{
return updateUserAction(mapping,form,request,response);
}
else if(myaction.equalsIgnoreCase("showUserList"))
{
return showUserList(mapping,form,request,response);
}
return null;
}这个是我的action 我还有另外一个类似的managerAction 这两个我代码都几乎一样,可是那个可以显示managerList 这个就不行 不知道为什么 ,断点就设在
String myaction = mapping.getParameter();
运行时根本不停
public class UserAction extends Action{public class UserAction extends DispatchAction {
继承错了 试试继承DispatchAction
type="usermodule.UserAction"
name="userForm"
parameter="showUserList"
scope="request"
input="/root/user/userlist.jsp">
<forward name="success" path="/root/user/userlist.jsp"></forward>
</action> 你的action配置了parameter, 那应该是要继承DispatchAction的
我另外一个public class ManagerAction extends Action为什么又能用呢?
我这个不是使用DispatchAction的啊,我是通过传进来的参数在execute方法中判断调用下面哪个方法来实现的,其中上面代码的其他方法都可以使用就是“showUserList”这个不行 不知道为什么
type="usermodule.UserAction"
name="userForm"
parameter="addUser"
validate="true"
scope="request"
input="/root/user/register.jsp">
<forward name="return_index" path="/index.jsp"></forward>
</action>
<action path="/userAction/modify"
type="usermodule.UserAction"
name="userForm"
parameter="updateUser"
validate="true"
scope="request"
input="/root/user/userinfo.jsp">
<forward name="return_userinfo" path="/root/user/userinfo.jsp"></forward>
</action>
<action path="/userAction/deleteUser"
type="usermodule.UserAction"
name="userForm"
parameter="deleteUser"
scope="request">
<forward name="success" path="/root/user/userlist.jsp"></forward>
</action>
<action path="/userAction/showUserList"
type="usermodule.UserAction"
name="userForm"
parameter="showUserList"
scope="request"
input="/root/user/userlist.jsp">
<forward name="success" path="/root/user/userlist.jsp"></forward>
</action>
这样子是应该不用继承dispatchAction的
type="usermodule.UserAction"
name="userForm"
parameter="showUserList"
scope="request"
input="/root/user/userlist.jsp">
<forward name="success" path="/root/user/userlist.jsp"></forward>
</action> 你的action配置了parameter, 那应该是要继承DispatchAction的要不就不用 在页面上放个隐藏字段 <input type="" name="method" value="showUserList"/>
UserAction 用String myaction =request.getParameter("method")接收
UserAction 用String myaction =request.getParameter("method")接收
要把 配置文件中的parameter 去掉
你觉得这应该是什么问题?我在描述我的问题:
关于参数传递我是通过同一个Action(userAction)配置多个Action-mapping来解决的 <action path="/userAction/register"
type="usermodule.UserAction"
name="userForm"
parameter="addUser"
validate="true"
scope="request"
input="/root/user/register.jsp">
<forward name="return_index" path="/index.jsp"></forward>
</action>
<action path="/userAction/modify"
type="usermodule.UserAction"
name="userForm"
parameter="updateUser"
validate="true"
scope="request"
input="/root/user/userinfo.jsp">
<forward name="return_userinfo" path="/root/user/userinfo.jsp"></forward>
</action>
<action path="/userAction/deleteUser"
type="usermodule.UserAction"
name="userForm"
parameter="deleteUser"
scope="request">
<forward name="success" path="/root/user/userlist.jsp"></forward>
</action>
<action path="/userAction/showUserList"
type="usermodule.UserAction"
name="userForm"
parameter="showUserList"
scope="request"
input="/root/user/userlist.jsp">
<forward name="success" path="/root/user/userlist.jsp"></forward>
</action>
<action path="/userAction/userinfo"
type="usermodule.UserAction"
name="userForm"
parameter="userInfo"
scope="request"
input="/root/user/userinfo.jsp">
<forward name="success" path="/root/user/userinfo.jsp"></forward>
</action>
mapping如上,其中里面的register试过是没有问题的,其他还没有测试,但在另外一个模块中我试过了里面的全部都没有问题。在action中设置的断点发现没有在该断点停下,运行时,点击显示所有用户,直接跳到userlist页面没有显示错误,但是没有userlist信息。如果是参数问题不至于连action execute方法都没有执行啊? 起码也得显示错误啊
LZ像你这样多个映射对应一个Action的话, 你不同的action应该有不同的处理请求的方法,你就那样搞,所有的action都跑去调用execute, 这样是你想要的吗.?
初学struts,这个是在一本书里的例子看来的,会有什么问题吗?
LZ你这样当然会有问题.! 你什么请求都给一个方法处理.. 不是不可以处理, 要你写很多if,你不会觉得很臃肿吗.? 随着你的action越来越多, if也越来越多?
你要是想多个路径映射到一个action的类又有不同的处理方法,
继承DispatchAction, 方法名不要叫execute了, 随便起个名, 但是在你struts的配置文件中的action中的parameter定义一个名字. 然后在页面上发送请求的时候, 加一个请求参数,get/post请求都可以,
name就为parameter的name,value为方法名!