Answer the question
In order to leave comments, you need to log in
How to properly pass value from INPUT form to servlet?
Hello.
I'm trying to get a value from a form in a servlet
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<form method="POST" action="DinamicInsertInOracle" enctype="multipart/form-data">
<div class="container">
<form class="row">
<br><br><br>
<table class="table">
<TR>
<td colspan="2"> Должно быть так
<div class="row">
<div class="col-lg-8">
<div class="input-group">
<select class="selectpicker show-tick form-control" >
<c:forEach var="row" items="${rs_derection.rows}">
<c:set var="DIRECTION" value="${row.DIRECTION}"/>
<optgroup label=${DIRECTION}>
<c:forEach var="row" items="${rs_position.rows}">
<c:set var="POSITION" value="${row.POSITION}"/>
<option >${POSITION}</option>
</c:forEach>
</optgroup>
</c:forEach>
</select>
<!-- /btn-group -->
</div>
</div>
</div>
<c:set var="SCRIPT">
select * from crm.PARAMETERS
</c:set>
<sql:query var="parameters" dataSource="jdbc/DBOracle">
${SCRIPT}
</sql:query>
<table>
<TR>
<td>
<div class="panel panel-default">
<div class="panel-heading">Основные показатели</div>
<table class="table">
<c:forEach var="row" items="${parameters.rows}">
<c:set var="ID" value="${row.NUM}"/>
<c:set var="SOLUTION" value="${row.SOLUTION}"/>
<c:set var="PARAMETER_VALUE" value="${row.VALUE}"/>
<tr>
<td> <input type="checkbox" NAME="CHECKBOX_${ID}"></td> <td style="width:50%">${SOLUTION}</td>
<td><div class="input-group"><input type="text" class="form-control" NAME="TEXT_${ID}" value="${PARAMETER_VALUE}"> <span class="input-group-addon">,%</span> </div></td>
<td>CHECKBOX_${ID} TEXT_${ID}</td>
</tr>
</c:forEach>
</table>
<div class="modal-footer">
<!-- <button type="button" class="btn btn-info" data-dismiss="modal"><i class="glyphicon glyphicon-remove"></i> Close</button> -->
<button value="Save" class="btn btn-success" type="submit" id="submit"><i class="glyphicon glyphicon-inbox"></i> Сохранить</button>
</div>
</div>
</td>
</TR>
</form>
@WebServlet(
name = "DinamicInsertInOracle",
description = "Insert Data To DB",
urlPatterns = "/check_db/DinamicInsertInOracle"
)
public class DinamicInsertInOracle extends HttpServlet {
private String dbURL = "jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=хост)(PORT=123)))(CONNECT_DATA=(SERVICE_NAME=сири)))";
private String dbUser = "имя";
private String dbPass = "пароль";
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");
response.setCharacterEncoding("UTF-8");
// gets values of text fields
String TEXT_ALL = request.getParameter("TEXT_1");
Answer the question
In order to leave comments, you need to log in
The reason for this behavior is the use of enctype="multipart/form-data" .
Or remove enctype, because it makes no sense here,
either hang the @MultipartConfig annotation on the servlet ,
or get the request data via request.getPart()
It works without enctype="multipart/form-data", BUT I decided to try it anyway and request.getParts() tried to apply the following
for (Part p: request.getParts())
{
TEXT_ALL=TEXT_ALL+p.getName();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question