I am using Spring MVC controller.
Below is my JSP code in which it will show three radio button. One is Insert, second radio button is Update and third radio button is Delete.
Once I click Insert radio button, it show two text box next to Insert radio button, and same thing with other two radio button.
<script type="text/javascript">
function doDisplay(radio) {
switch (radio.value) {
case "Insert":
document.getElementById("inserts").style.display = "inline";
document.getElementById("updates").style.display = "none";
document.getElementById("delete").style.display = "none";
break;
case "Update":
document.getElementById("inserts").style.display = "none";
document.getElementById("updates").style.display = "inline";
document.getElementById("delete").style.display = "none";
break;
case "Delete":
document.getElementById("inserts").style.display = "none";
document.getElementById("updates").style.display = "none";
document.getElementById("delete").style.display = "inline";
break;
}
}
</script>
<body>
<form method="post" action="testOperation">
<input type="radio" name="tt" value="Insert"
onclick="doDisplay(this);" /> Insert <input type="hidden" name="name" value="insert"><span id="inserts"
style="display: none"> <label for="Node"> Node </label> <input
type="text" name="node" size="20" /> <label for="Data"> Data </label>
<input type="text" name="data" size="100" />
</span> <br /> <input type="radio" name="tt" value="Update"
onclick="doDisplay(this);" /> Update <input type="hidden" name="name" value="update"> <span id="updates"
style="display: none"> <label for="Node"> Node </label> <input
type="text" name="node" size="20" /> <label for="Data"> Data </label>
<input type="text" name="data" size="100"/>
</span> <br /> <input type="radio" name="tt" value="Delete"
onclick="doDisplay(this);" /> Delete <input type="hidden" name="name" value="delete"><span id="delete"
style="display: none"> <label for="Node"> Node </label> <input
type="text" name="node" size="20" /> <label for="Data"> Data </label>
<input type="text" name="data" size="100"/>
</span> <br />
<input type="submit">
</form>
Now what I am trying to do is as soon as I click on Insert radio button, it will show me two textbox next to Insert radio button. And after putting some values inside those two text box, I press submit button on the form. And then it goes to testOperations method in which name field has these many things -
insert,update,delete
How can I force it to have only one field which I am clicking only? Meaing if I am clickign insert radio button, then name variable should have insert value? Below is my method -
#RequestMapping(value = "testOperation", method = RequestMethod.GET)
public Map<String, String> testOperation() {
final Map<String, String> model = new LinkedHashMap<String, String>();
return model;
}
#RequestMapping(value = "testOperation", method = RequestMethod.POST)
public Map<String, String> testOperations(#RequestParam String name,
#RequestParam String node,
#RequestParam String data) {
final Map<String, String> model = new LinkedHashMap<String, String>();
System.out.println(name);
System.out.println(node);
System.out.println(data);
return model;
}
Meaning, Suppose I click Insert radio button and type Hello in the first text and World in the second text box, then I will hit the submit button, and after that I should see insert value in the name variable and hello value in the node variable and world value in the data variable.
And same thing with update and delete.
Is this possible to do?
You have done correct. All you need to do is while click the radio button set the value on name. One hidden variable is enough. Your html part look like this,
<form method="post" action="testOperation">
<!-- I used only one hidden box to store value -->
<input type="hidden" name="name" id="dynamicName">
<input type="radio" name="tt" value="Insert"
onclick="doDisplay(this);" /> Insert <span id="inserts"
style="display: none"> <label for="Node"> Node </label> <input
type="text" name="node" size="20" /> <label for="Data"> Data </label>
<input type="text" name="data" size="100" />
</span> <br /> <input type="radio" name="tt" value="Update"
onclick="doDisplay(this);" /> Update <span id="updates"
style="display: none"> <label for="Node"> Node </label> <input
type="text" name="node" size="20" /> <label for="Data"> Data </label>
<input type="text" name="data" size="100"/>
</span> <br /> <input type="radio" name="tt" value="Delete"
onclick="doDisplay(this);" /> Delete <span id="delete"
style="display: none"> <label for="Node"> Node </label> <input
type="text" name="node" size="20" /> <label for="Data"> Data </label>
<input type="text" name="data" size="100"/>
</span> <br />
<input type="submit">
</form>
And in script,
<script type="text/javascript">
function doDisplay(radio) {
switch (radio.value) {
case "Insert":
document.getElementById("inserts").style.display = "inline";
document.getElementById("updates").style.display = "none";
document.getElementById("delete").style.display = "none";
document.getElementById("dynamicName").value = "insert";
break;
case "Update":
document.getElementById("inserts").style.display = "none";
document.getElementById("updates").style.display = "inline";
document.getElementById("delete").style.display = "none";
document.getElementById("dynamicName").value = "update";
break;
case "Delete":
document.getElementById("inserts").style.display = "none";
document.getElementById("updates").style.display = "none";
document.getElementById("delete").style.display = "inline";
document.getElementById("dynamicName").value = "delete";
break;
}
}
</script>
Hope this helps.
You have inputs with same names, you don't need other hidden. A single node and data inputs are enough
This HTML is enough:
<input type="radio" name="tt" value="Insert" onclick="doDisplay(this);" /> Insert<br/>
<input type="radio" name="tt" value="Update" onclick="doDisplay(this);" /> Update<br/>
<input type="radio" name="tt" value="Delete" onclick="doDisplay(this);" /> Delete<br/>
<label for="Node"> Node </label> <input type="text" name="node" size="20" /><br/>
<label for="Data"> Data </label> <input type="text" name="data" size="100"/><br/>
<input type="submit">
Here is the controller function:
public Map<String, String> testOperations(
#RequestParam(value="tt", required=false) String name,
#RequestParam(value="node", required=false) String node,
#RequestParam(value="data", required=false) String data) {
//...
}
Related
i have 2 entity class, parkingUser and parkingDetails, user can have many parking details(one to many).
parkingUserobject contain: [id, firstName, lastName,parkingDetails[id, entryDate,...,user_id(FK)]]
in parkingUser i had List of parkingDetails(its my FK)
#OneToMany(mappedBy = "parkingUsers", cascade = CascadeType.ALL, orphanRemoval = true)
private List<parkingDetails> parkingDetails = new ArrayList<parkingDetails>();
so now i have a thymeleaf page that recive from controller model of user and model of parking, its showing exist data on form input fields, and adding more data of exit date and exit time on the object in the c'tor on the controller that recive the form.
after that what i want to achive is to get the id of parking.id,
but its send me from a form the id of user.id
my controller with prints to understood what i get from the form:
(lets say i enter to form on user id =1, its create on the controoler new object of parkingDetails, and save it on db,
after that i want to delete the new object that created with id 35, and the object that pass from the form of parking.id, but i cant access this data.
#PostMapping("/saveDateAndTimeOfExitParking")
public String saveNewUserFromFormAction(
#ModelAttribute("user") parkingUsers parkingUsers,
#ModelAttribute("details") parkingDetails parkingDetails) {
//need to store to details table date and time
String str = LocalTime.now().format(DateTimeFormatter.ofPattern("HH:mm:ss"));
System.out.println(parkingUsers);
//parkingUsers [id=1, firstName=David, lastName=Adams, license=2356584, parkingDetails=[]]
System.out.println(parkingDetails);
//parkingDetails [id=1, entryDate=2022-05-18, entryTime=08:35:20, exitDate=null, exitTime=null, parkingUsers=null]
System.out.println(parkingUsers.getParkingDetails());
//[]
parkingDetails d = new parkingDetails(
parkingDetails.getEntryDate(),
parkingDetails.getEntryTime(),
LocalDate.now(),
str);
d.setParkingUsers(parkingUsers);
parkingDetailsService.saveParkingUser(d);
//store the object of parking details on new db of history
//and then remove it from main schema
System.out.println(d.getId());
//35
System.out.println(parkingDetails.getId());
//1
parkingDetailsService.deleteParkingEntrySession(d.getId());
//i want to delete also the parkingDetails object from the form, but its gave me the id of parkingUser
//parkingDetailsService.deleteParkingEntrySession(parkingDetails.getId());
return "redirect:/exit";
}
my form:
<div class="formCenterAndWidth">
<form action="#" th:action="#{/saveDateAndTimeOfExitParking}" method="POST">
<input type="hidden" th:field="*{user.id}"/>
<div class="form-group row">
<label class="col-sm-2 col-form-label">User Id:</label>
<div class="col-sm-10">
<input readonly class="form-control" type="text" th:field="*{user.id}">
</div>
<label class="col-sm-2 col-form-label">Parking Id:</label>
<div class="col-sm-10">
<input readonly class="form-control" type="text" th:field="*{parking.id}">
</div>
<label class="col-sm-2 col-form-label">First Name:</label>
<div class="col-sm-10">
<input class="form-control" type="text" th:field="*{user.firstName}">
</div>
<label class="col-sm-2 col-form-label">Last Name:</label>
<div class="col-sm-10">
<input readonly class="form-control" type="text" th:field="*{user.lastName}">
</div>
<label class="col-sm-2 col-form-label" style="white-space: nowrap;">License Number</label>
<div class="col-sm-10">
<input readonly class="form-control" type="text" th:field="*{user.license}">
</div>
<label class="col-sm-2 col-form-label">Entry Date</label>
<div class="col-sm-10">
<input readonly class="form-control" type="text" th:field="*{parking.entryDate}">
</div>
<label class="col-sm-2 col-form-label">Entry Time</label>
<div class="col-sm-10">
<input readonly class="form-control" type="text" th:field="*{parking.entryTime}">
</div>
<label class="col-sm-2 col-form-label">Exit Date</label>
<div class="col-sm-10">
<input readonly class="form-control" type="text" th:value="${#dates.format(exitDateAndTime, 'dd-MM-yyyy')}">
</div>
<label class="col-sm-2 col-form-label">Exit Time</label>
<div class="col-sm-10">
<input readonly class="form-control" type="text" th:value="${#dates.format(exitDateAndTime, 'HH:mm:ss')}">
</div>
<br><br>
<button type="submit" class="btn btn-info col-7 center">Exit Car</button>
</div>
</form>
I am sending text values from jsp to servlet but in servlet request.getParameter() gives me null values. Below I am mentioning my JSP, Servlet and web.xml
REGISTER.JSP
<form id="contactform" action="servlet/SaveInfo" method="post">
<p class="contact"><label for="email">Email</label></p>
<input id="email" name="email" placeholder="example#domain.com" required="" tabindex="1" type="email">
<p class="contact"><label for="username">User Name</label></p>
<input id="username" name="username" placeholder="username" required="" tabindex="2" type="text">
<p class="contact"><label for="password">Password</label></p>
<input type="password" id="password" name="password" required="" tabindex="3">
<p class="contact"><label for="repassword">Confirm Password</label></p>
<input type="password" id="repassword" name="repassword" required="">
<p class="contact"><label for="phone">Mobile Phone</label></p>
<input id="phone" name="phone" placeholder="phone number" required="" tabindex="4" type="text"> <br>
<p class="contact"><label for="name">Organization Name</label></p>
<input id="Orgname" name="name" placeholder="Organization name" required="" tabindex="5" type="text">
<p class="contact"><label for="Address">Address</label></p>
<input id="address" name="name" placeholder="Street,Area,city" required="" tabindex="6" type="text"> <br>
<!-- <select class="select-style" name="BirthMonth"> -->
<label>State</label><br>
<select class="select-style" name="BirthMonth">
<%
ResultSet rs = null;
Connection con = null;
PreparedStatement pmst1= null;
int countryid = 208;
try{
con = DBConnectivity.getOracleDBConnection();
pmst1 = con.prepareStatement(Sqlquery.getRegion());
pmst1.setInt(1, countryid);
rs=pmst1.executeQuery();
while(rs.next()){
String name = rs.getString("name");
%>
<option value="<%=name %>"><%=name %></option>
<% } %>
<%
}catch(Exception e){
}
%>
</select><br><br>
<p class="contact"> <input id="check" name="name" style="margin-right: 10px" type="checkbox">
<label for="name"> Not Yet Registered GSTIN</label> </p>
<p class= "GSTIN"><label for="GSTIN">GSTIN No.</label></p><br>
<input id = "GSTINNO" maxlength="15" name= "GSTIN" placeholder="GSTIN No." type ="text"><br><br>
<input class="buttom" name="submit" id="submit" tabindex="5" value="Sign me up!" type="submit">
SaveInfo.java
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try{
ResultSet rs = null;
Connection con = null;
PreparedStatement pmst1= null;
String Orgname = request.getParameter("Orgname");
String check =request.getParameter("check");
String GSTINNO = request.getParameter("GSTINNO");
con = DBConnectivity.getOracleDBConnection();
int clientid = 1000014;
MClient Client = new MClient (Env.getCtx(), clientid, null);
I want all the values in my servlet class and save that values in database below I am mentioning my web.xml file
Kindly help me out
<servlet>
<description></description>
<display-name>SaveInfo</display-name>
<servlet-name>SaveInfo</servlet-name>
<servlet-class>com.org.register.SaveInfo</servlet-class>
<servlet-mapping>
<servlet-name>SaveInfo</servlet-name>
<url-pattern>/servlet/SaveInfo</url-pattern>
</servlet-mapping>
In Servlet you need to get parameters by name attribute, not id.
For example, You have the following,
<input id="Orgname" name="name" placeholder="Organization name" required="" tabindex="5" type="text">
Here you have given id to be Orgname and name parameter is name. So in Servlet you will do,
request.getParameter("name");
But you are doing,
String Orgname = request.getParameter("Orgname");
Secondly, you cannot have same name for two parameters. For both the following you have given name to be name
<input id="Orgname" name="name" placeholder="Organization name" required="" tabindex="5" type="text">
<input id="address" name="name" placeholder="Street,Area,city" required="" tabindex="6" type="text"> <br>
Give some different name to the parameters.
The getParameter function of request object works with name attribute. So please replace your jsp with following.
<form id="contactform" action="servlet/SaveInfo" method="post">
<p class="contact"><label for="email">Email</label></p>
<input id="email" name="email" placeholder="example#domain.com" required="" tabindex="1" type="email">
<p class="contact"><label for="username">User Name</label></p>
<input id="username" name="username" placeholder="username" required="" tabindex="2" type="text">
<p class="contact"><label for="password">Password</label></p>
<input type="password" id="password" name="password" required="" tabindex="3">
<p class="contact"><label for="repassword">Confirm Password</label></p>
<input type="password" id="repassword" name="repassword" required="">
<p class="contact"><label for="phone">Mobile Phone</label></p>
<input id="phone" name="phone" placeholder="phone number" required="" tabindex="4" type="text"> <br>
<p class="contact"><label for="name">Organization Name</label></p>
<input id="Orgname" name="Orgname" placeholder="Organization name" required="" tabindex="5" type="text">
<p class="contact"><label for="Address">Address</label></p>
<input id="address" name="address" placeholder="Street,Area,city" required="" tabindex="6" type="text"> <br>
<!-- <select class="select-style" name="BirthMonth"> -->
<label>State</label><br>
<select class="select-style" name="BirthMonth">
<%
ResultSet rs = null;
Connection con = null;
PreparedStatement pmst1= null;
int countryid = 208;
try{
con = DBConnectivity.getOracleDBConnection();
pmst1 = con.prepareStatement(Sqlquery.getRegion());
pmst1.setInt(1, countryid);
rs=pmst1.executeQuery();
while(rs.next()){
String name = rs.getString("name");
%>
<option value="<%=name %>"><%=name %></option>
<% } %>
<%
}catch(Exception e){
}
%>
</select><br><br>
<p class="contact"> <input id="check" name="name" style="margin-right: 10px" type="checkbox">
<label for="name"> Not Yet Registered GSTIN</label> </p>
<p class= "GSTIN"><label for="GSTIN">GSTIN No.</label></p><br>
<input id = "GSTINNO" maxlength="15" name= "GSTIN" placeholder="GSTIN No." type ="text"><br><br>
<input class="buttom" name="submit" id="submit" tabindex="5" value="Sign me up!" type="submit">
JSP post parameters using their attribute name. you wrote the wrong attribute name in 3 parameters.
Change:
<input id="check" name="name"
<input id="Orgname" name="name"
<input id="address" name="name"
To:
<input id="check" name="check"
<input id="Orgname" name="Orgname"
<input id="address" name="address"
I'm trying to insert data into database using PreparedStatement based on form input. The program follows normal flow when user clicks "submit" on the checkout page (checkout.jsp) the form redirect him to the confirmation.jsp as wanted but no data gets inserted. When user submit forms, the program seems to ignore the PreparedStatement and only notices the userPath. I wonder what could be the cause of this behavior? No error gets printed.
Servlet.java
} else if (userPath.equals("/purchase")) {
String OD = request.getParameter("OD");
String FN = request.getParameter("FN");
String LN = request.getParameter("LN");
String PN = request.getParameter("PN");
String EM = request.getParameter("EM");
String A1 = request.getParameter("A1");
String A2 = request.getParameter("A2");
String CT = request.getParameter("CT");
String SPR = request.getParameter("SPR");
String PZC = request.getParameter("PZC");
String CTRY = request.getParameter("CTRY");
String referenceNumber = request.getParameter("referenceNumber");
String status = request.getParameter("status");
String queue = request.getParameter("queue");
String cart_total = request.getParameter("cart_total");
String order_details = request.getParameter("order_details");
try{
Class.forName("com.mysql.jdbc.Driver");
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost/application?user=root&password=12345");
PreparedStatement pst;
pst = connection.prepareStatement("insert into customer_order(date_created, first_name,last_name,phone,email,address_1,address_2,city,State_Province_Region,Postal_Zip_Code,country,referenceNumber,status,queue,cart_total,order_details) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
//When concating strings you should do something like st = connection.prepareStatement("Insert into student values ('" + userid + "','"+pw+"')"); but the right way is
//st = connection.prepareStatement("Insert into student values (1,2)");
pst.setString(1,OD);
pst.setString(2,FN);
pst.setString(3,LN);
pst.setString(4,PN);
pst.setString(5,EM);
pst.setString(6,A1);
pst.setString(7,A2);
pst.setString(8,CT);
pst.setString(9,SPR);
pst.setString(10,PZC);
pst.setString(11,CTRY);
pst.setString(12,referenceNumber);
pst.setString(13,status);
pst.setString(14,queue);
pst.setString(15,cart_total);
pst.setString(16,order_details);
pst.executeUpdate();
}catch(ClassNotFoundException | SQLException ex){
//print a message or something
}finally{
Connection connection = null;
if (connection!=null){
try {
connection.close();
} catch (SQLException ex) {
Logger.getLogger(ControllerServlet.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
userPath = "/confirmation";
}
Checkout.jsp
<form id="shipping_form" method="post" action="purchase" name="checkout">
<label for="date" class="shp_label">Order Date </label>
<input id="date" name="OD" type="text" class="shp_ipt" value="<%= new java.util.Date()%>" readonly>
<label for="fname" class="shp_label">First Name </label>
<input id="fname" name="FN" type="text" class="shp_ipt" required>
<label for="lname" class="shp_label">Last Name </label>
<input id="lname" name="LN" type="text" class="shp_ipt" required>
<label for="phone" class="shp_label"> Phone </label>
<input id="phone" name="PN" type="text" class="shp_ipt" required>
<label for="email" class="shp_label"> Email </label>
<input id="email" name="EM" type="email" class="shp_ipt" required>
<label for="add1" class="shp_label"> Address 1 </label>
<input id="add1" name="A1" type="text" class="shp_ipt" required>
<label for="add2" class="shp_label"> Address 2 </label>
<input id="add2" name="A2" type="text" class="shp_ipt">
<label for="city" class="shp_label"> City </label>
<input id="city" name="CT" type="text" class="shp_ipt" required>
<label for="spr" class="shp_label"> Region </label>
<input id="spr" name="SPR" type="text" class="shp_ipt" required>
<label for="pzc" class="shp_label"> Zip / Code </label>
<input id="pzc" name="PZC" type="text" class="shp_ipt" required>
<label for="country" class="shp_label"> Country </label>
<input id="country"name="CTRY" type="text" class="shp_ipt" required>
<input type="hidden" name="referenceNumber" value="<%=System.currentTimeMillis()%>" />
<input type="hidden" name="staus" value="Pending" />
<input type="hidden" name="queue" value="This information will be updated soon." />
<input type="hidden" class="cartTotal" style="border:none; background:transparent;" name="cart_total" readonly type="text" value="${cart.total}"/>
<input type="hidden" name="order_details" value="Your order is being processed." />
<input class="submit_button button" name="submit" value="Ship Me!" type="submit">
</form>
If you have no error found then you can change some code in preparedStatement . Like this -
pst = connection.prepareStatement("insert into customer_order values('"+FN+"', '"+LN+"',.........) ");
And one think remember that after PreparedStatement it is must be perform execute() method , by PreparedStatement's object . Like this -
pst.execute();
I have a Html page called kind.html inside the WEB-INF directory and an other jsp page called registration.jsp inside the WEB-INF folder. I need to put this registration.jsp page inside the WEB-INF directory so it cannot be accessible if a user attempts to get access to it by typing its URL. So my problem is how can i navigate from kind.html to registration.jsp with link called home I am newbie in this Thank you.
below is my code snippet and png file
kind.html..............................................
<li class='active'><a href='kind.html'><span>Home</span></a></li>
<li class='has-sub'><span>Register</span>
.............................registrationcontroller........................................
#RequestMapping(value="/registration",method = RequestMethod.POST)
public #ResponseBody
String firstRegistration(HttpServletRequest req,
HttpServletResponse response) {
response.setContentType("text/html");
RegistrationModel registrationModel = new RegistrationModel();
registrationModel.setFirstName(req.getParameter("first_name"));
System.out.println("controller " + req.getParameter("first_name") );
registrationModel.setLastName(req.getParameter("last_name"));
registrationModel.setPassword(req.getParameter("password"));
registrationModel.setEmailID(req.getParameter("email"));
System.out.println("controller email " + req.getParameter("email"));
SimpleDateFormat format = new SimpleDateFormat("yyyy-mm-dd");
try {
Date date = format.parse(req.getParameter("BirthDate"));
registrationModel.setDOB(date);
} catch (Exception e) {
e.printStackTrace();
}
String phoneno=req.getParameter("phoneNo");
Integer phoneNo = Integer.parseInt(phoneno);
System.out.println("phone no ...."+phoneNo);
registrationModel.setPhoneNo(phoneNo);
registrationModel.setGender(req.getParameter("gender"));
String age=req.getParameter("Age");
Long AGE = Long.parseLong(age);
registrationModel.setAge(AGE);
registrationModel.setAvtar(req.getParameter("Avtar"));
System.out.println("avtar"+ req.getParameter("Avtar"));
Address address = new Address();
address.setAddressline(req.getParameter("Full-Address"));
address.setCity(req.getParameter("city"));
address.setLandmark(req.getParameter("landmark"));
address.setState(req.getParameter("state"));
String zipCode =req.getParameter("Zipcode");
Long zipcode = Long.parseLong(zipCode);
address.setZipcode(zipcode);
registrationModel.setAddress(address);
registrationService.resgistration(registrationModel);
return "registration.jsp";
}
..........................registration.jsp.........................................................
<form action="registration" method="post">
<fieldset>
<legend>Register Form</legend>
<div>
<input type="text" name="first_name" placeholder="First Name" />
</div>
<div>
<input type="text" name="last_name" placeholder="Last Name" />
</div>
<div>
<input type="password" name="password" placeholder="Password" />
</div>
<div>
<input type="text" name="email" placeholder="Email" />
</div>
<div>
<input type="text" name="BirthDate" placeholder="BirthDate" />
</div>
<div>
<input type="number" name="Age" placeholder="Age" />
</div>
<div>
<select name="gender">
<option value="select">i am..</option>
<option value="m">Male</option>
<option value="f">Female</option>
</select><br> <br>
</div>
<div>
<input type="number" name="phoneNo" placeholder="PhoneNo" />
</div>
<div>
<input type="text" name="Full-Address"
placeholder="Full-Address" />
</div>
<div>
<input type="text" name="landmark" placeholder="landmark" />
</div>
<div>
<input type="text" name="city" placeholder="city" />
</div>
<div>
<input type="text" name="state" placeholder="state" />
</div>
<div>
<input type="number" name="Zipcode" placeholder="Zipcode" />
</div>
<div>
<input type="file" name="Avtar" placeholder="Avtar" />
</div>
<input type="submit" name="submit" value="Send" />
</fieldset>
</form>![folder structure of project][2]
1st to call your pages html is static so you can use mvc resources "" for it, for jsp you have to use ViewResolver for jstl use InternalResourceViewResolver in its configuration as :
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver" >
<property name="prefix">
<value>/WEB-INF/view/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
then in your controller use
return "registration";
also you will need method to handle GET request and change below line
<li class='has-sub'><span>Register</span>
if you are using Spring boot you will find these configuration automated.
I made a web project from jsp and hibernate, on my from have a checkbox... I got no problem when insert the data but when update the data I got this [Ljava.lang.String in every first checkbox on my form and the value of my first checkbox doesn't store to database but the other checkbox work well
one more thing how to check the checkbox value from database??
this part of my jsp
<td><spring:message code="authorityRight" text="default text" /></td>
<td>:</td>
<td><fieldset id="menu_e">
<input type="checkbox" name="menu" value="User" class="ceksmenu">User<br />
<fieldset id="sub_menu_user_e">
<input type="checkbox" name="sub_menu_user" value="User1" class="ceksmuser">User1
<input type="checkbox" name="sub_menu_user" value="User2" class="ceksmuser">User2
<input type="checkbox" name="sub_menu_user" value="User3" class="ceksmuser">User3<br />
</fieldset>
<input type="checkbox" name="menu" value="Monitoring" class="ceksmenu">Monitoring<br />
<fieldset id="sub_menu_monitoring_e">
<input type="checkbox" name="sub_menu_monitoring" value="Monitoring1" class="ceksmmonit">Monitoring1
<input type="checkbox" name="sub_menu_monitoring" value="Monitoring2" class="ceksmmonit">Monitoring2
<input type="checkbox" name="sub_menu_monitoring" value="Monitoring3" class="ceksmmonit">Monitoring3<br />
</fieldset>
<input type="checkbox" name="menu" value="Parameter" class="ceksmenu">Parameter<br />
<fieldset id="sub_menu_parameter_e">
<input type="checkbox" name="sub_menu_parameter" value="Parameter1" class="ceksmparam">Parameter1
<input type="checkbox" name="sub_menu_parameter" value="Parameter2" class="ceksmparam">Parameter2
<input type="checkbox" name="sub_menu_parameter" value="Parameter3" class="ceksmparam">Parameter3</fieldset>
</fieldset>
</td>
this is my javascript
<script type="text/javascript">
$(document).ready(function() {
$('.update').click(function() {
var id_update = $(this).attr("id_update");
var nama_authority = $(this).attr("nama_authority");
var menu = $('input:checkbox[name=menu]').is(':checked');
var sub_menu_user = $('input:checkbox[name=sub_menu_user]').is(':checked');
var sub_menu_monitoring = $('input:checkbox[name=sub_menu_monitoring]').is(':checked');
var sub_menu_parameter = $('input:checkbox[name=sub_menu_parameter]').is(':checked');
$('#id_authority_e').val(id_update);
$('#id_authority_l').val(id_update);
$('#nama_authority_e').val(nama_authority);
$('#menu_e').val(menu);
$('#sub_menu_user_e').val(sub_menu_user);
$('#sub_menu_monitoring_e').val(sub_menu_monitoring);
$('#sub_menu_parameter_e').val(sub_menu_parameter);
});
$('.delete').click(function() {
var id_delete = $(this).attr("id_delete");
$('#id_authority_d').val(id_delete);
});
$('#example').dataTable({
});
});
</script>
and this is my controller
public class Operator {
#RequestMapping(value = "/admin/updateAuthority.html", method = RequestMethod.POST)
public ModelAndView updateAuthorityUser(ModelMap model, HttpServletRequest request,
HttpServletResponse response) throws Exception {
String id_Authority = request.getParameter("id_authority");
AuthorityUser authorityuser = authorityuserService.get(id_Authority);
String nama = request.getParameter("nama_authority");
String[] menu = request.getParameterValues("menu");
String[] sb_user = request.getParameterValues("sub_menu_user");
String[] sb_monitor = request.getParameterValues("sub_menu_monitoring");
String[] sb_parameter = request.getParameterValues("sub_menu_parameter");
authorityuser.setId_authority(id_Authority);
authorityuser.setNama_authority(nama);
authorityuser.setMenu(menu);
authorityuser.setSub_menu_user(sb_user);
authorityuser.setSub_menu_monitoring(sb_monitor);
authorityuser.setSub_menu_parameter(sb_parameter);
authorityuserService.update(authorityuser);
model.addAttribute("successUpdate", "true");
return listAuthorityUser(model);
}
}
any help will be pleasure :)