I feel like a complete idiot, for the last 5 hours at work I’m trying to figure out Spring and how to do this.
I have a form inside “checklist.jsp” and I want to take the data that the user puts into the form. I will use that data later, but I just want to capture it now…
I have checklist.jsp which has a controller called “ChecklistController.java”.
Here is my form in checklist.jsp
<form method="POST" action="checklist.jsp">
<table>
<tr>
<td>FQDN:</td>
<td colspan="2"><input type='text' id="FQDN" /></td>
<td><input type="radio" id="rdoScript" /></td>
<td>Script 1 </td>
<td><input type="radio" id="rdoScript" /></td>
<td>Script 2</td>
</tr>
</table>
<input type="submit" value="Run" id="selectionSubmit" />
</form>
Please note: I was using tags but I changed it so I could actually see the page. I’ve been playing with it back and forth.
This is my ChecklistController.java
@Controller
// handling methods are relative to this controller
public class ChecklistController {
private ChecklistService service;
private static final Log LOG = LogFactory.getLog(ChecklistController.class);
@RequestMapping("/checklist")
public ModelAndView checklist() throws Exception{
ModelAndView mavChecklist = new ModelAndView("checklist");
mavChecklist.addObject("test",service.simpleTest());
mavChecklist.addObject("date",service.getDateTime());
return mavChecklist;
}
@Autowired
public void setService(ChecklistService service){
this.service = service;
}
}
My idea was to get the data into a bean, so I made this class. UserSel.java
public class UserSel implements java.io.Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private String script;
private String FQDN;
public UserSel(){
}
public String getFQDN() {
return FQDN;
}
public void setFQDN(String fqdn) {
FQDN = fqdn;
}
public String getScript() {
return script;
}
public void setScript(String script) {
this.script = script;
}
}
I hope I provided enough information.
I want to take the FQDN and the Script selection and be able to use those selections from the user (to run remote scripts).
Please let me know if additional information is required — I’m frustrated with Spring at the moment 🙁
EDIT:
Adding current ChecklistController.java
@Controller
// handling methods are relative to this controller
public class ChecklistController {
private ChecklistService service;
private static final Log LOG = LogFactory.getLog(ChecklistController.class);
@RequestMapping("/checklist")
public ModelAndView checklist(@ModelAttribute(value="UserSel")UserSel userSel) throws Exception{
ModelAndView mav = viewRender();
String FQDN = userSel.getFQDN();
String getScript = userSel.getScript();
mav.addObject("FQDN", FQDN);
mav.addObject("script",getScript);
return mav;
}
@RequestMapping("/newchecklist")
public ModelAndView viewRender() {
ModelAndView mav=new ModelAndView();
mav.addObject("UserSel ", new UserSel ());
mav.setViewName("checklist");
return mav;
}
@Autowired
public void setService(ChecklistService service){
this.service = service;
}
}
1) add spring’s form tld. and rewrite your form like this
2.Modify you controller to get the submited values.
As you didn’t provide more code like context files, i need to take certain assumptions.