之前用的很好,但是最近改了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>
<%@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>
这里是student不用 可以省略
登陆ID:<input name="id"/><br>
登陆密码:<input name="password"/><br>
这样只要你action中存在id password两个属性就可以 (get set)
如果你action中存在student,那就确认下是否存在set方法
我都设成一样了也不行,还是null
xml文件:
<action name="loginAction" class="com.tfsp.action.LoginAction" method="login">
<result >/studentList.jsp</result>
<result name="error">/error.jsp</result>
</action>之前没有配form也没问题的,要是配的话怎么配呢?
document.forms[0].submit();
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;
}
}