Java 在servlet中使用JSP文件中的数据

Java 在servlet中使用JSP文件中的数据,java,html,jsp,servlets,Java,Html,Jsp,Servlets,以下是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.ex

以下是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中下拉列表中所选元素的索引。有一种方法。我认为索引,但我不能在这里使用它。

使用
selectObject.selectedIndex
from


您可以在选择selectedIndex时或提交之前使用selectedIndex设置selectbox值


您可以在选择selectedIndex时或提交之前使用selectedIndex设置selectbox值

这很好,但我希望在servlet中使用此索引,而不是在JSP文件中使用此索引,这就是为什么我说,在某个隐藏字段中设置值,或者在提交或更改时选择框值,这很好,但我想在servlet中使用此索引,而不是在JSP文件中。这就是为什么我说,在某个隐藏字段中设置值,或者在提交或更改时选择框值
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);
        }

}