av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

您的位置:首頁技術文章
文章詳情頁

帶有jsp:useBean的Javabean它們如何工作?我不明白

瀏覽:102日期:2024-05-14 16:27:11
(adsbygoogle = window.adsbygoogle || []).push({}); 如何解決帶有jsp:useBean的Javabean它們如何工作?我不明白?

我在index.jsp和Servlet之間又做了一個jsp文件:

<jsp:useBean scope='session'/><jsp:setProperty name='binop' property='*'/>.

這做到了“魔術”。

解決方法

我必須使用Java bean從jsp文件中獲取2個數字和一個運算。提交數字后,將它們從該Java Bean帶到servlet并返回它們的結果。問題是Javabean字段永遠不會用文本框中寫的數字來完成。所以,我有了index.jsp的主體:

<html><head> <meta http-equiv='Content-Type' content='text/html; charset=UTF-8'> <title>JSP Page</title> <link rel='stylesheet' type='text/css' href='http://m.4tl426be.cn/wenda/style.css' /></head><body> <h1>Calculator</h1> <FORM METHOD='POST' action='Controller'>N1: <input type ='text' name='nr1' value='0'>op: <input type ='text' name='op' value='+'>N2: <input type ='text' name='nr2' value='0'><INPUT TYPE='submit' NAME='actiune' VALUE='Calculate'/> </FORM> <jsp:useBean scope='session'/> <jsp:setProperty name='binOp' property='*'/></body>

servlet的processRequest方法Controller.java放在程序包servlet中:

protected void processRequest(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException { response.setContentType('text/html;charset=UTF-8'); PrintWriter out = response.getWriter(); HttpSession session = request.getSession(true); BinaryOperation binOp = (BinaryOperation) session.getAttribute('binOp'); try {if (!binOp.isComplete()) { System.out.println(binOp.getNr1() + binOp.getNr2() + binOp.getOp()); response.sendRedirect('index.jsp');} else { out.println('<html>'); out.println('<head>'); out.println('<title>Servlet Controller</title>'); out.println('</head>'); out.println('<body>'); out.println('<h1>Bean in controller ' + binOp.getNr1() + '__' + binOp.getOp() + '__' + binOp.getNr2() + '</h1>'); out.println(binOp.toString()); out.println('</body>'); out.println('</html>');} } finally {out.close(); }}

然后將bean BinaryOperation放入程序包bean中:

package beans;public class BinaryOperation {private String nr1;private String op;private String nr2;public void setNr1(String nr1) { this.nr1 = nr1;}public void setOp(String op) { this.op = op;}public void setNr2(String nr2) { this.nr2 = nr2;}public String getNr1() { return nr1;}public String getOp() { return op;}public String getNr2() { return nr2;}public boolean isComplete() { return !(((nr1 == null) || (nr1.length() == 0)) || ((op == null) || (op.length() == 0)) || ((nr2 == null) || (nr2.length() == 0)));}}

在Apache日志中,我有if語句的下一個輸出(請參閱servlet-System.out.println(binOp.getNr1()+binOp.getNr2()+ binOp.getOp());):nullnullnull

我的錯誤在哪里?

標簽: java
相關文章:
主站蜘蛛池模板: 亚洲一级淫片 | 天天草av| 99精品国产一区二区三区 | 久久久久久国产精品免费 | www精品美女久久久tv | 9久久精品 | 男女又爽又黄视频 | www.亚洲成人网 | 在线视频一区二区 | 国产精品久久久乱弄 | 国产精品69毛片高清亚洲 | 国产色片在线 | 国产成人综合一区二区三区 | 欧美精品免费观看二区 | 久久毛片| 欧美成人一级 | 91直接看| 91成人精品 | 国产精品一区一区 | 又爽又黄axxx片免费观看 | 国产精品久久久久久久久久久新郎 | 欧美a区| 你懂的av | 国产精品久久久久久久久久尿 | 欧美精品一区二区三区一线天视频 | 一区二区小视频 | а√中文在线8 | 久久av一区二区三区 | 欧美精品乱码99久久影院 | 午夜天堂精品久久久久 | 欧美精品成人 | 亚洲成人免费网址 | 亚洲av毛片成人精品 | 国产精品成人国产乱一区 | 手机三级电影 | 精品视频亚洲 | 中文字幕免费视频 | 国产精品成人在线 | 一区二区精品 | 五月综合色啪 | 在线第一页 |