I have a form in my JSP which has a list box.
I want on submit of the form, I do some server side validation on and then duplicate the list box and append it to jsp again?
Can someone help me know how we can achieve this ?
Jsp :
<form:form commandName="user">
<div id="primaryList">
<select name="data" size="5" id="s">
<option value=""></option>
</select>
</div>
</form:form>
I know we can do it using javascript, but I need validation done on server side before duplicating.
Related
I have a JSP page and a Spring boot controller, in the jsp i have a form with a select and options when i choose the option i need to pass that value to a java code to transform WSDL to java classes. How can i do it?
<form id="form" action="genclasses" method="post">
<select name="WSDLcat" class="custom-select ml-2" id="inputGroupSelect04">
<%
ServiceClass[] services = (ServiceClass[]) request.getAttribute("services");
%>
<c:forEach items="${services}" var="service">
<option id="WSDL" value="${service.getWsdl()}">
${service.getNombre()}</option>
</c:forEach>
</select>
<input class="btn btn-outline-secondary align-right" id="genclases" type="submit" onclick="generarClases()" value="Generar Clases">
</form>
String[] params= {"-d","./src/main/resources/generatedFiles","HERE I NEED THE VALUE OF THE OPTION"};
WSDLToJava.main(params);
ZipUtil.pack(new File("./src/main/resources/generatedFiles"), new File("./src/main/resources/generated.zip"));
I cannot do it in java inserted in jsp becasuse i need to use different libraries and i do not know how to pass it to the controller or do it in the same page. Any help?
Could anyone please explain me how to avoid the duplicate enters of records in to the select box options during editing the page.I am using java to develop web application I am very new to that,I need to remove the duplicates from the select box option while editing.Could anyone please help me .
Sample Code
<td><select property="employeestatus" value="" id="employeestatus">
<c:if test="${employee.employeestatus!=null}">
<option value="${employee.employeestatus}">${employee.employeestatus}</option>
</c:if>
<option value="">Select</option>
<option value="Active">Active</option>
<option value="Terminated">Terminated</option>
<option value="Deceased">Deceased</option>
<option value="Resigned">Resigned</option>
<option value="InActive">InActive</option>
</select>
<html:errors property="employeestatus"/>
<p id="employeestatus" style="color:red"/>
</td>
I would suggest to add the selected attribute on the option corresponding to your "employeestatus" variable instead of duplicating this option on the first line.
See HTML option selected Attribute
By the <html:errors ...>, I gess you use Struts 1. If it's true, I would use the
<html:select ...> tag and
<html:options or optionsCollection ...>
with java Map store in some context (servlet, session or request) to configure options. That struts tag will select the good option corresponding to your variable value.
See Struts <html:select ...> doc
The index page of the site will ask user to select a stage area. I want to pass their selection from page to page until they log out or return to this selection.
I have searched long and hard but just don't know how to phrase that question to a web search. Just need a little push in the right direction. Form code below and thanks in advance.
<form name="pick" method="POST" action="http://wavepick.htm">
<table border="0">
<tr VALIGN="TOP">
<td width="177">
<select id="stageChoice" name="stageArea">
<option selected value=" ">(Select Staging Area)</option>
<option value="A">A </option>
<option value="B">B </option>
</select>
</div>
<input type="submit" name="Submit" value="Stage" name="B1">
<input type="hidden" name="request_id" value="wavepick">
</form>
You can store the selected value between pages in a session variable.
If you want to do this only with HMTL/Javascript, you have to submit this form via "GET" (instead "POST"), and at each page you need to send again "stageArea" to the another page, so:
Page1.html?stageArea=B
Page2.html?stageArea=B
Page3.html?stageArea=B
That's how you read GET parameters via Javascript: How can I get query string values in JavaScript?
Ya, it's very arduous just with HTML/Javscript.
But you have mentioned "log out", do you have back-end (like PHP, ASP.NET,etc..)? With back-end language it'll be much more easier, you could store stageArea on session once, and just read it at each page.
If you are using a backend language such as PHP you can store that value in a $_SESSION variable. and access it wherever you need during that session.
Here is the documentation for the session variables:
PHP Session
If not, let me know and i'll figure out a different method for you.
This question already has answers here:
How can I retain HTML form field values in JSP after submitting form to Servlet?
(2 answers)
Closed 7 years ago.
Here is my code, how can i retain the values of the form when i click on the hyper reference link.(a href: bottom of the code)
<form action="APPServlet">
<div class="">
<div class="">Search For:</div>
<div class="">
<input type="text" size="45" align="right" name="searchRequest">
</div>
</div>
<div class="">
<div class="">Exclude:</div>
<div class="">
<input type="text" size="45" align="right" name="excludeWords">
</div>
</div>
<div class="">
<div class="">In Modules:</div>
<div class="">
<select name="modules">
<option name="module" value="all">All modules</option>
<c:forEach var="module" items="${modelObj.modules}">
<option name="module" value="${module}">${module}</option>
</c:forEach>
</select>
</div>
</div>
</form>
<!-- ahref outside the form , this does not work
&searchRequest=${searchRequest} <- Guess the value is out of scope
-->
<div class="div-table-row">
<div class="div-table-single-col">
${question.id} ${question.topic}
</div>
</div>
You have several possibilities, and all involve JavaScript.
When clicking on the link, change its href using JavaScript by appending all the values of the inputs of the form as parameters of the URL
When clicking on the link, add a hidden field to the form containing the question ID, change the action of the form to make it go to MCQApp instead of going to APPServlet, and submit the form
The cleanest one: when clicking on the link, send an AJAX request to a URL which responds with an HTML fragment (or data), and replace the section of the page that you want to update with this HTML fragment, thus leaving the form as it is in the page.
There are two ways, if you're working with a session, store it as an attribute of your session. But if you're not using sessions, you can use Cookies, just store the values you want in a new cookie and then call the cookie and obtain the values.
Sessions are cookies as well, but they have another functions, the cookies are simplier and help you to store values that you can reuse later. Best regards
Keep the data passed in a model and use it in the jsp like,
Keep all your Input variables in search model object and update it whenever search is called.Keep searchRequest in the request attribute before rendering the response.
Given the following HTML:
<form action="" name="<%=rs.getString(1)%>" method="post">
<select name="opcao">
<option value="Did not like">Did not like</option>
<option value="Ok">Ok</option>
<option value="Liked" selected="selected">Liked</option>
<option value="Loved!">Loved!</option>
</select>
</form>
Is it possible to get the name of the form and from the select tag to the same servlet as different parameters?
HTML form name is NOT submitted as part of the request. Although if you want, you can pass as form hidden field as below:
<form name="myForm" action="/my_servlet">
<input type="hidden" name="htmlFormName" value="myForm"/>
....
However if you have two form fields, then they are passed to servlet and can be accessed using request.getParameter("fieldName") method inside the servlet..