寻求你的帮助。
问题:在高层次上,问题是我们在jsp中从java脚本设置的隐藏文件到达了模型对象。
1-我jave JSP 2-具有控制器,可扩展多功能控制器 3-模型对象
我的JS:
ARD.save = function(url){
var query = "?method=save";
var jsonArray = [];
$('#submitbutton').click(function() {
$("input:checkbox:checked").each(function(){
var jsonObj = {};
jsonObj.id = $(this).attr("id");
/* jsonObj.name = $(this).attr("value"); */
jsonArray.push(jsonObj);
});
alert (" all values - "+JSON.stringify(jsonArray,0,"\t"));
document.getElementById('selectedIds').setAttribute('value', JSON.stringify(jsonArray,0,"\t"));
alert ("values1 - "+document.getElementById('selectedIds').value);
$('#result').text(document.getElementById('selectedIds').value);
});
JSP:
<form method="POST" name="xxxxx" id="xxxxxx">
<h1>testing started.</h1>
<%-- <input type="hidden" id="selectedIds" value="${model.setlectedValue}" /> --%>
<input type="hidden" id="selectedIds" id="selectedIds" value="" />
<table border="1" name="myTable" id="myTable">
<thead>
<tr>
<th><input type="checkbox" id="selectall" />SelectAll</th>
<th>ID</th>
<th>Name</th>
<th>Date</th>
</tr>
</thead>
<tbody>
<c:forEach var="value" items="${model.values}">
<tr>
<td align="center"><input type="checkbox" class="case"
id="${value.empid}" name="agreementNumber" value="${value.empid}" /></td>
<td>${value.empid}</td>
<td>${value.name}</td>
<td>${value.date}</td>
</tr>
</c:forEach>
</tbody>
</table>
<input type="button" name="submitbutton" id="submitbutton" value="submit Button"
onclick="ARD.save('<c:url value="/tbletest.htm" />');" />
</form>
<div id="result">
Controller :
public class LoginController extends MultiActionController { //SimpleFormController{ //
/*public LoginController(){
setCommandClass(Login.class);
setCommandName("loginForm");
}*/
private TableModel model;
public TableModel getModel() {
return model;
}
public void setModel(TableModel model) {
this.model = model;
}
public LoginController(){
model=new TableModel();
}
//@Override
public ModelAndView save(HttpServletRequest request, HttpServletResponse response) throws Exception {
//Login login = (Login) command;
//return new ModelAndView("loginSuccess","login",login);
System.out.println("save method.");
System.out.println(" model.getSetlectedValue() -> "+ model.getSetlectedValue());
System.out.println("request object : - "+request.getAttribute("selectedIds"));
System.out.println(" request.getParameter(\"selectedIds\") : - "+ request.getParameter("selectedIds"));
System.out.println(" model stestvalue: - "+ model.getTestValue());
//return new ModelAndView("loginSuccess");
//return new ModelAndView("tbletest");
return new ModelAndView("tbletest","model",model);
}
型号:
public class TableModel {
private List<TableValues> values;
private Object setlectedValue;
private String testValue;
春天configuraiton的应用上下文:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/jsp/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/welcome.htm">welcomeController</prop>
<prop key="/helloWorld.htm">helloController</prop>
<prop key="/tbletest.htm">loginController</prop>
</props>
</property>
</bean>
<bean id="hello`enter code here`Controller" class="com.wisdomjobs.HelloController" />
<bean id="welcomeController" class="com.wisdomjobs.WelcomeController">
<property name="methodNameResolver" ref="methodNameResolver" />
</bean>
<bean id="loginController" class="com.kruders.controller.LoginController">
<property name="methodNameResolver" ref="methodNameResolver" />
</bean>
<bean id="methodNameResolver"
class="org.springframework.web.servlet.mvc.multiaction.ParameterMethodNameResolver">
<property name="paramName" value="method" />
<property name="defaultMethodName" value="defaultMethod" />
</bean>
</beans>
当我尝试从控制器获取隐藏字段(selectedIds)的值时,我得到空值,因为当我在jsp的div标签中设置时,它显示我在java脚本中设置的json值。
你能帮我吗?enter code here
答案 0 :(得分:0)
要以表格形式发送参数,您必须设置名称属性。在selectedIds
:
<input type="hidden" id="selectedIds" name="selectedIds" value="" />