[英]Using data from JSP file in servlet
这是JSP:
<%@ page language="java" contentType="text/html; charset=windows-1256"
pageEncoding="windows-1256"%>
<%@page import="com.exalt.servlets.LoginServlet"%>
<%@page import="com.exalt.classes.MCategory"%>
<%@page import="com.exalt.classes.SCategory"%>
<!DOCTYPE htmlPUBLIC"//W3C//DTDHTML4.01Transitional//EN""http://www.w3.org/TR/html4/loose. dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256">
<title>Add sub category</title>
</head>
<body>
<h2>add a category</h2>
<form method="post" action="AddSubCategServlet">
name <input type="text" name="subcategory" style="margin:10px"><br><br>
Main category
<select size="1" id="MCategory" title="" name="MCategory">
<option value="">Select a main category</option>
<%
for( MCategory elem : LoginServlet.MCList) {
%>
<option value=<%=elem.getName()%>><%= elem.getName()%></option>
<%} %>
</select><br><br>
<input type="submit" value="Add">
</form>
</body>
</html>
这是servlet:
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String sub= request.getParameter("subcategory");
String main= request.getParameter("MCategory");
SCategory SCat=new SCategory(sub);
MCategory selected = LoginServlet.MCList.get(0);
request.getRequestDispatcher("CategDetails.jsp").forward(request, response);
}
}
我想使用servlet下拉列表中所选元素的索引。 我认为有一种方法.index但在这里我不能使用它
使用http://www.w3schools.com/jsref/prop_select_selectedindex.asp中的 selectObject.selectedIndex
您可以在自行选择时或在提交之前使用selectedIndex设置selectbox值
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.