Struts2的form无法提交到action

救生圈 2012-09-05 03:27:41
之前用的很好,但是最近改了jsp之后提交到action的form就是null了,怎么回事呢 ?

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>IPDASSSS</title>
<link rel="stylesheet" type="text/css" href="themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="themes/icon.css">
<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="js/jquery.easyui.min.js"></script>
<script>
function dosubmit() {
document.loginForm.enctype="multipart/form-data";
document.loginForm.submit();
}

</script>
</head>

<body>
<form id="loginform" name="loginForm" action="loginAction" method="post">
<div id="loginin" class="easyui-window" closable="false" draggable="false" resizable="false" title="欢迎登陆" style="width:300px;height:120px;">
登陆ID:<input name="student.id"/><br>
登陆密码:<input name="student.password"/><br>
<a class="easyui-linkbutton" iconCls="icon-ok" onclick="dosubmit()">登陆</a>
</div>
</form>
</body>
</html>

...全文
229 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
mengshan007 2012-11-05
  • 打赏
  • 举报
回复
楼主问题解决了没?
救生圈 2012-09-05
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 的回复:]

student的get,set方法写了吗
[/Quote]
我又重新生成了一遍,还是不行
package com.tfsp.action;

import java.util.List;
import java.util.Map;

import org.apache.struts2.interceptor.RequestAware;

import com.opensymphony.xwork2.ActionSupport;
import com.tfsp.model.Student;
import com.tfsp.service.StudentService;


public class LoginAction extends ActionSupport implements RequestAware{
private StudentService studentService;
private Student student;
//对应HttpRequest作用域,由RequestAware注入
private Map request;
public String login(){
boolean b = studentService.login(student);
if(b){
List<Student> studentList = studentService.getAllStudent();
request.put("studentList", studentList);
return SUCCESS;
}else{
return "error";
}

}


public StudentService getStudentService() {
return studentService;
}

public void setStudentService(StudentService studentService) {
this.studentService = studentService;
}





/**
* @return the student
*/
public Student getStudent() {
return student;
}


/**
* @param student the student to set
*/
public void setStudent(Student student) {
this.student = student;
}


public Map getRequest() {
return request;
}


public void setRequest(Map request) {
this.request = request;
}


}
救生圈 2012-09-05
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 的回复:]

引用 7 楼 的回复:
引用 4 楼 的回复:

id="loginform" name="loginForm" 两者值要么一样,要么写一个,不然document.loginForm根本找不到。


我都设成一样了也不行,还是null


document.forms[0].submit();
[/Quote]

这么写也不行
aikaibo 2012-09-05
  • 打赏
  • 举报
回复
没导入Student这个类啊.
Cactus_hxk 2012-09-05
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 的回复:]
引用 4 楼 的回复:

id="loginform" name="loginForm" 两者值要么一样,要么写一个,不然document.loginForm根本找不到。


我都设成一样了也不行,还是null
[/Quote]

document.forms[0].submit();
fuguitong163 2012-09-05
  • 打赏
  • 举报
回复
student的get,set方法写了吗
  • 打赏
  • 举报
回复
loginAction代码发上来
救生圈 2012-09-05
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]

看看loginForm在Struts的xml文档中有没有配置
[/Quote]

xml文件:
<action name="loginAction" class="com.tfsp.action.LoginAction" method="login">
<result >/studentList.jsp</result>
<result name="error">/error.jsp</result>
</action>

之前没有配form也没问题的,要是配的话怎么配呢?
救生圈 2012-09-05
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 的回复:]

id="loginform" name="loginForm" 两者值要么一样,要么写一个,不然document.loginForm根本找不到。
[/Quote]

我都设成一样了也不行,还是null
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]
引用 1 楼 的回复:

loginAction.action

能提交到后台,但是student为null
[/Quote]

这里是student不用 可以省略
登陆ID:<input name="id"/><br>
登陆密码:<input name="password"/><br>
这样只要你action中存在id password两个属性就可以 (get set)
如果你action中存在student,那就确认下是否存在set方法
di_wq 2012-09-05
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 的回复:]
id="loginform" name="loginForm" 两者值要么一样,要么写一个,不然document.loginForm根本找不到。
[/Quote]
四楼正解,希望楼主早点解决问题
  • 打赏
  • 举报
回复
id="loginform" name="loginForm" 两者值要么一样,要么写一个,不然document.loginForm根本找不到。
Cactus_hxk 2012-09-05
  • 打赏
  • 举报
回复
看看loginForm在Struts的xml文档中有没有配置
救生圈 2012-09-05
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]

loginAction.action
[/Quote]
能提交到后台,但是student为null
anqinxiaozhu 2012-09-05
  • 打赏
  • 举报
回复
loginAction.action

81,091

社区成员

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

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