2

我想通过jsp将从用户获取的值打印到另一个页面。取值是整数。异常错误即将到来,值为空。请帮助我如何打印该值?

错误由于这条线。错误为空值作为输出。代码:

<jsp:useBean id="account" scope="session" class="com.servlet.Message1" >
 <%  String acc1 = request.getParameter("acc");
 int acc = Integer.parseInt(acc1);
 account.setAccount(acc);


 %> </jsp:useBean>
4

1 回答 1

0

试试这个

//ch01_01.jsp
<HTML>
  <HEAD>
    <TITLE>A JSP Example</TITLE>
  </HEAD>

  <BODY>
    <H1>Using JSP</H1>
    <% out.println("No worries."); %>
  </BODY>
</HTML>


//ch01_02.html
<HTML>
    <HEAD>
        <TITLE>Reading Text Fields</TITLE>
    </HEAD>

    <BODY>
        <H1>Reading Text Fields</H1>
        <FORM ACTION="ch01_03.jsp" METHOD="POST">
            Enter your name:
            <INPUT TYPE="TEXT" NAME="text1">
            <BR>
            <INPUT TYPE="SUBMIT" value="Submit">
        </FORM>
    </BODY>
</HTML>

//ch01_03.jsp
<HTML>
  <HEAD>
    <TITLE>Reading Data From Text Fields</TITLE>
  </HEAD>

    <BODY>
        <H1>Reading Data From Text Fields</H1>
        Your name is 
        <% out.println(request.getParameter("text1")); %>
   </BODY>
</HTML>

//ch01_07.jsp
<HTML>
    <HEAD>
        <TITLE>Using a Bean</TITLE>
    </HEAD>

    <BODY>
        <H1>Using a Bean</H1>

    <% beans.ch01_04 messenger = new beans.ch01_04(); %>
    The bean says: <%= messenger.message() %> 

    </BODY>
</HTML>

//ch01_07.jsp
<HTML>
    <HEAD>
        <TITLE>Using Bean Properties</TITLE>
    </HEAD>

    <BODY>
        <H1>Using Bean Properties</H1>

        <jsp:useBean id="bean1" class="beans.ch01_06" />

        The bean says: <jsp:getProperty name="bean1" property="message" /> 
        <BR>
        <jsp:setProperty name="bean1" property="message" value="No Problem." />

        Now the beans says: <jsp:getProperty name="bean1" property="message" />
    </BODY>
</HTML>
于 2013-11-14T09:43:25.410 回答