request parameters from jsp in java without using

2019-08-28 04:47发布

问题:

I want to request parameters in a java file from a jsp without using servlets. Does anyone know how to do this? I believe its something to do with setting an attribute but I'm new to java so its all a learning game from me. I want to send the lotsize and bedrooms parameters to the java file. My jsp file is shown below and i need to know what to put in my java file in order to retrieve these parameters

回答1:

Create a JSP file as shown below. Also Create a java file com.test.Room and pass the value to the Class

<%@ page import = "com.test.Room"%>

<html>
<body>

<%
   String bedRooms = request.getParameter("bedrooms");
   String lotSize = request.getParameter("lotSize");
%>
<ul>
    <li><p><b>bedrooms</b>
       <%=bedRooms%>
    </p></li>
    <li><p><b>lotsize</b>
       <%=lotSize%>
    </p></li>
 </ul>
<%
   Room room = new Room(bedRooms, lotSize);
   //Other logic, if any
%>
 <body>
 <html>