アクションで ajax 呼び出しからnull 値を取得する ( FirstList.java )...最初のリストが正しく読み込まれます。助けが必要です、私はstruts2と休止状態が初めてです。
StudentRegistration.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib uri="/struts-tags" prefix="s"%>
<%@taglib uri="/struts-dojo-tags" prefix="sx"%>
<html>
<head>
<sx:head />
<title>Student Registration</title>
</head>
<script>
function show_details() {
dojo.event.topic.publish("show_detail");
}
</script>
<body>
<s:form id="form1" name="form1" action="StudentRegister" method="post" enctype="multipart/form-data" theme="simple">
<s:hidden name="id" />
<table border="0">
...
<tr>
<td><s:label value="Course " for="course" /></td>
<td><s:select name="course" list="courseList" onchange="javascript:show_details();return false;" /></td>
</tr>
<tr>
<td colspan="2"><s:url id="durl" action="secload" /><sx:div showLoadingText="" id="details" href="%{durl}" listenTopics="show_detail" formId="form1" ></sx:div></td>
</tr>
<tr>
<td align="center" colspan="2"><s:submit /></td>
</tr>
</table>
</s:form>
</body>
</html>
詳細.jsp
<%@taglib uri="/struts-tags" prefix="s"%>
<%@taglib uri="/struts-dojo-tags" prefix="sx"%>
<table border="0" width=100%>
<s:if test="branchList != null">
<tr><td><s:select name="branch" list="branchList" label="Branch"></s:select></td></tr></s:if>
<s:if test="semList != null">
<tr><td><s:select name="sem" list="semList" label="Semester" /></td></tr></s:if>
</table>
FirstList.java
package bharat;
public class FirstList extends ActionSupport {
private String course;
private Map<Integer,Integer> semList=null;
private Map<String, String> branchList=null;
public String execute() throws Exception
{
populateTwo(getCourse());
return SUCCESS;
}
public void populateTwo(String id1)
{
// Get null value for id1
System.out.println (id1);
if(id1!=null&&!id1.equals(""))
{
semList=new HashMap<Integer,Integer>();
branchList=new HashMap<String,String>();
if (id1.equalsIgnoreCase("B.Tech.")||id1.equalsIgnoreCase("M.Tech.")) {
branchList.put("CSE","CSE");
branchList.put("ECE","ECE");
branchList.put("MAE","MAE");
branchList.put("CHE","CHE");
branchList.put("CVE","CVE");
branchList.put("IT","IT");
} else if (id1.equalsIgnoreCase("MCA")) {
branchList.put("CS","CS");
branchList.put("EC","EC");
branchList.put("MA","MA");
branchList.put("CIV","CIV");
branchList.put("IT","IT");
}
else{branchList.put("None","None");}
if (id1.equalsIgnoreCase("B.Tech.")||id1.equalsIgnoreCase("Bio.Tech.")) {
semList.put(1,1);
semList.put(2,2);
semList.put(3,3);
semList.put(4,4);
semList.put(5,5);
semList.put(6,6);
semList.put(7,7);
semList.put(8,8);
setSemList(semList);
} else if (id1.equalsIgnoreCase("M.Tech.")) {
semList.put(1,1);
semList.put(2,2);
semList.put(3,3);
semList.put(4,4);
} else {
semList.put(1,1);
semList.put(2,2);
semList.put(3,3);
semList.put(4,4);
semList.put(5,5);
semList.put(6,6);
}
}
}
public String getCourse() {
return course;
}
public void setCourse(String course) {
this.course = course;
}
public Map<Integer,Integer> getSemList() {
return (this.semList);
}
public void setSemList(Map<Integer,Integer> semList) {
this.semList = semList;
}
public void setBranchList(Map<String, String> branchList) {
this.branchList = branchList;
}
public Map<String, String> getBranchList() {
return branchList;
}
}
Struts.xml
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="default" extends="hibernate-default">
...
<action name="StudentRegister" class="bharat.RegistrationAction">
<interceptor-ref name="defaultStackHibernate">
<param name="fileUpload.allowedTypes">image/png,image/gif,image/jpeg</param>
</interceptor-ref>
<result name="input">/jsp/StudentRegistration.jsp</result>
<result name="success">/jsp/success2.jsp</result>
</action>
**<action name="linkStudentRegister" method="populateOne" class="bharat.RegistrationAction">
<result name="success">/jsp/StudentRegistration.jsp</result>
</action>
<action name="secload" class="bharat.FirstList">
<result name="success">/jsp/Detail.jsp</result>
</action>**
</package>
</struts>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>CourseRegistrationModule</display-name>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
RegistrationAction.java
package bharat;
public class RegistrationAction extends ActionSupport implements ModelDriven<Register>,ServletRequestAware {
private Register register = new Register();
private RegisterDAO registerDAO = new RegisterDAOImpl();
private HttpServletRequest servletRequest;
private Map<String,String> courseList= null;
public String populateOne()
{
System.out.println ("populateone");
courseList=new HashMap<String,String>();
courseList.put("B.Tech.","B.Tech.");
courseList.put("M.Tech.","M.Tech.");
courseList.put("MCA","MCA");
courseList.put("Bio.Tech.","Bio.Tech.");
return SUCCESS;
}
public Map<String,String> getCourseList() {
return (this.courseList);
}
public void setCourseList(Map<String,String> courseList) {
this.courseList = courseList;
}
@Override
public Register getModel() {
//TODO
return register;
}
@Override
public void setServletRequest(HttpServletRequest servletRequest) {
this.servletRequest = servletRequest;
}
public String execute() {
...
return SUCCESS;
}
public Register getRegister() {
return register;
}
public void setRegister(Register register) {
this.register = register;
}
}