我想通过jsp将用户的值打印到另一个页面。取值是整数。异常错误即将发生,该值为null。请帮我看看如何打印价值?
错误由于此行。错误为空值作为输出。 代码:
<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>
答案 0 :(得分:0)
尝试this:
//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>