Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java JSP获取html类型=数字输入字段的值_Java_Html_Jsp_Javabeans_Jsp Tags - Fatal编程技术网

Java JSP获取html类型=数字输入字段的值

Java JSP获取html类型=数字输入字段的值,java,html,jsp,javabeans,jsp-tags,Java,Html,Jsp,Javabeans,Jsp Tags,因此,我必须制作一种提供工具作为学习JSP的家庭作业,其基本原理是客户机进入索引站点并输入数据,然后他被重定向到第二个页面,该页面向他显示所有计算过的内容的完整提供 表单如下所示: <form method="POST" action="offer.jsp"> <table> <tr> <td>Name:</td><td><input type="text" name="

因此,我必须制作一种提供工具作为学习JSP的家庭作业,其基本原理是客户机进入索引站点并输入数据,然后他被重定向到第二个页面,该页面向他显示所有计算过的内容的完整提供

表单如下所示:

<form method="POST" action="offer.jsp">
    <table>
        <tr>
            <td>Name:</td><td><input type="text" name="name"></td>
        </tr>
        <tr>
            <td>Addresse:</td><td><input type="text" name="address"></td>
        </tr>
        <tr>
            <td>Boden in m²:</td><td><input type="number" name="area" min="1" value="10"></td>
        </tr>
        <tr>
            <td>Anzahl der R&auml;ume mit bis zu 15m²:</td><td><input type="number" name="rooms_15" min="0"</td>
        </tr>
        <tr>
            <td>Anzahl der R&auml;ume mit bis zu 25m²:</td><td><input type="number" name="rooms_25" min="0"></td>
        </tr>
        <tr>
            <td>Anzahl der R&auml;ume mit bis zu 40m²:</td><td><input type="number" name="rooms_40" min="0"></td>
        </tr>
        <tr>
            <td>Anzahl der WC-R&auml;ume:</td><td><input type="number" name="toiletrooms" min="0"></td>
        </tr>
        <tr>
            <td>Anzahl der WCs insgesamt:</td><td><input type="number" name="toilets" min="0"></td>
        </tr>
        <tr>
            <td>Anzahl der B&auml;der:</td><td><input type="number" name="bathrooms" min="0"></td>
        </tr>
        <tr>
            <td>Anzahl der K&uuml;chen:</td><td><input type="number" name="kitchens" min="0"></td>
        </tr>
    </table>
    <br>
    <input type="submit" value="Berechnen" onclick="<%
        offer.setName(request.getParameter("clientname"));
        offer.setAddress(request.getParameter("address"));
        System.out.print("\n\n\n"+request.getParameter("area")+"\n\n\n");       // S.O.P. for testing reasons
//                    offer.setArea(request.getParameter("area"));
       %>; location.href = 'offer.jsp'">
</form>
我只是为了测试而摆弄这片土地。计划是将所述输入的值设置到我的JavaBean,但是request.getParameterarea;即使我使用htmls value=10给它一个默认值,它仍然保持null。我已经发现输入需要以某种形式工作,但仅此而已。问题不在于我的JavaBean或类似的东西,因为正常的textfield Name和Address字段工作得非常好,并且在下一页上正确显示

希望有人能帮助我

你诚挚的,
我建议您学习使用jsp和servlet实现MVC。这会解决你的问题你的方法是非常错误的。这不是填补空缺的正确方法beans@UmeshKumarSharma你能告诉我应该如何更改代码以便正确填充bean吗?我举了一个例子来说明如何做。让我为你建立一个例子。我不太明白,我如何在我的第二页上进一步使用bean?只需在我的offer.jsp页面上使用,或者我必须在该页面上创建一个控制器并从该控制器获取bean吗?我也不太确定是否允许我们使用MVC,因为我们还没有涉及它。
    **MVC Architecture with JSP and Servlet**

    **Model**

    public class StudentBean {

        private int rno;
        private String name;
        private float fee;

        public StudentBean() {

        }

        public int getRno() {
            return rno;
        }

        public void setRno(int rno) {
            this.rno = rno;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public float getFee() {
            return fee;
        }

        public void setFee(float fee) {
            this.fee = fee;
        }

        @Override
        public String toString() {
            return "StudentBean [rno=" + rno + ", name=" + name + ", fee=" + fee + "]";
        }

    }

    **View**

        <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
            pageEncoding="ISO-8859-1"%>
        <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
        <html>
        <head>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
        <title>Insert title here</title>
        </head>
        <body>

            <form  method="get" action="StudentController">

                Rno: <input type="text" name="rno"/> <br/>
                Name: <input type="text" name="name"/> <br/>
                Fee: <input type="text" name="fee"/> <br/>
                <input type="submit" name="btnSubmit" value="Submit"/>
            </form>
        </body>
        </html>

    **Controller**

    import java.io.IOException;
    import javax.servlet.ServletException;
    import javax.servlet.annotation.WebServlet;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;


@WebServlet("/StudentController")
public class StudentController extends HttpServlet {
    private static final long serialVersionUID = 1L;
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        StudentBean studentBean = new StudentBean();
        studentBean.setRno(Integer.parseInt(request.getParameter("rno")));
        studentBean.setName(request.getParameter("name"));
        studentBean.setFee(Float.valueOf(request.getParameter("fee")));


        System.out.println(studentBean);

        request.getSession().setAttribute("studentObject", studentBean);
        request.getServletContext().getRequestDispatcher("/output.jsp").forward(request, response);
    }

}

**another page, where bean is being used.**

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"   pageEncoding="ISO-8859-1"%>
<%@ page import="com.loardscrat.controller.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

<h1>Hello</h1>
<%
    StudentBean studentBean = (StudentBean) request.getSession().getAttribute("studentObject");
    out.print(studentBean.getRno());
    out.print(studentBean.getName());
    out.print(studentBean.getFee());

%>
</body>
</html>