我在struts里的action里取的直为什么老是取不到

dd121011 2008-04-15 04:08:26
public class LoginaAction extends Action {

public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
LoginForm ss=new LoginForm();
System.out.println(ss.getName());
System.out.println(ss.getPassword());
return null;
}
}
打印出来的都是null。。。
为什么取不到页面里输入的直啊?
问题出哪儿了?
...全文
105 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
forestking_xx 2008-04-15
  • 打赏
  • 举报
回复
是的,如果配置正确, 使用正确,那么这个form就是具体的LoginForm,(LoginForm是ActionForm的子类);
dd121011 2008-04-15
  • 打赏
  • 举报
回复
问题是不是出到这了?
public class LoginaAction extends Action {
/*
* Generated Methods
*/

/**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
LoginForm ss = (LoginForm) form;


actionForward里的这个form应该是“ActionForm”啊,还是应该是已经定义了的具体的那个form啊比如loginform?
dd121011 2008-04-15
  • 打赏
  • 举报
回复
struts-config的代码。。。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">

<struts-config>
<data-sources />
<form-beans >
<form-bean name="loginForm" type="com.dong.company.form.LoginForm" />

</form-beans>

<global-exceptions />
<global-forwards />
<action-mappings >
<action
attribute="loginAction"
name="loginAction"
path="/logina"
type="com.dong.company.action.LoginaAction"
input ="index.jsp">
<forward name="error" path="error.jsp" />
<forward name="success" path="success.jsp" />
</action>

</action-mappings>

<message-resources parameter="com.dong.company.ApplicationResources" />
</struts-config>
dd121011 2008-04-15
  • 打赏
  • 举报
回复
LoginForm该怎么配置啊?
我用myeclipse建完LoginForm然后再建loginaction,想添加loginform却找不到。。。只好手写了。。。
seeSkyblue 2008-04-15
  • 打赏
  • 举报
回复
struts-config里面LoginForm没有配好或者action标签里面写的form名字不对。
forestking_xx 2008-04-15
  • 打赏
  • 举报
回复
很有可能是你没有配置LoginForm, 建议你找个struts的例子先看看。
dd121011 2008-04-15
  • 打赏
  • 举报
回复
2008-4-15 16:39:43 org.apache.struts.action.RequestProcessor processException
警告: Unhandled Exception thrown: class java.lang.NullPointerException
2008-4-15 16:39:43 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet action threw exception
java.lang.NullPointerException
at com.dong.company.action.LoginaAction.execute(LoginaAction.java:47)
dd121011 2008-04-15
  • 打赏
  • 举报
回复
改成
LoginForm ss= (LoginForm)form
以后:
有空指针异常。。。。不知道为什么。。
严重: Servlet.service() for servlet action threw exception
java.lang.NullPointerException
at com.dong.company.action.LoginaAction.execute(LoginaAction.java:47)
fansy007 2008-04-15
  • 打赏
  • 举报
回复
LoginForm ss= (LoginForm)form
gongyali2005 2008-04-15
  • 打赏
  • 举报
回复
LoginForm ss=new LoginForm(); 这样写当然都是NULL了.
你根本就同有用提交后的FORM
System.out.println(ss.getName());
System.out.println(ss.getPassword());
return null;
要用这里的值
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)

67,538

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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