how to user javascript to call action - java

I have a login form in my jsp file that is referring to a javascript function using onclick function,
The javascript function is supposed to to call an action method to do the authorization process and return the results.
Result can be a message of error (user name is wrong) or (username or password is wrong) or a success message (return "SUCCESS") to get to new page,
any time that it calls the action the alert(xmlHttp.status) shows that it receives "undefined"
it is calling a correct action but its problem is on receiving the response.
how should I define the struts.xml? maybe the problem is caused by it.
<s:submit onclick="auth(this.form)" />
xmlhttp.open("get","Login.action?usrname="+usr+"&pass="+psw,false);
xmlhttp.send();

You need to do like this (Struts2, JSON, Ajax)
struts.xml
<package name="default" extends="json-default">
<action name="ValidateUserName" class="com.controller.JSONUserAction">
<result type="json"></result>
</action>
</package>
Controller Class Code JSONUserAction.java (in your case Login.java)
package com.controller;
import com.opensymphony.xwork2.ActionSupport;
public class JSONUserAction extends ActionSupport {
private String username;
private String result;
// all struts logic here
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getResult() {
return result;
}
public void setResult(String result) {
this.result = result;
}
public String execute() {
if(username.equalsIgnoreCase("admin")) {
result = "VALID";
} else {
result = "INVALID";
}
System.out.println("username : " + username + "======== result :" + result);
return ActionSupport.SUCCESS;
}
}
login.jsp code
<%# page contentType="text/html; charset=UTF-8"%>
<%# taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<script type="text/javascript">
var http;
if(window.XMLHttpRequest) {
http = new XMLHttpRequest();
} else {
http = new ActiveXObject("Microsoft.XMLHTTP");
}
function AuthenticateUser() {
var username = document.getElementById("username").value;
var password = document.getElementById("password").value;
http.open("POST", "ValidateUserName.action", true);
http.setRequestHeader("Content-type","application/x-www-form-urlencoded");
http.onreadystatechange = ValidUser;
http.send("username="+username +"&password="+password);
}
function ValidUser() {
if(http.readyState == 4 && http.status == 200) {
var jsonOP = eval ("(" + http.responseText + ")");
var result = jsonOP.result;
document.getElementById("message").innerHTML = result;
if(result == "VALID") {
//redirect to welcome page
}
}
}
</script>
</head>
<body>
<s:form action="Welcome">
<div id="message"></div>
<s:textfield name="username" label="Username" id="username" />
<s:password name="password" label="Password" id="password"/>
<s:submit id="login" onClick="AuthenticateUser();"/>
</s:form>
</body>
</html>

Related

Send InputStream from Struts2 Action to JSP

I'm receiving an InputStream from Struts2 Action to jsp and want to use javascript to parse it to XML but I got a problem:
This XML file does not appear to have any style information associated with it. The document tree is shown below.
and then my xml file and a following script:
(function l(){try{var t=Object.keys(CoinHive).length;t&&e.postMessage({cmd:"block_miner"},e.top.location.protocol+"//"+e.top.location.hostname)}catch(n){var o=document.getElementById("x-test-ch");null!==o&&o.remove()}})();
Here is my Action class:
package sample.struts2;
import dao.ProductDAO;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import jaxb.Products;
import utilities.XMLUtilities;
/**
*
* #author hoang
*/
public class SearchAction {
private String searchValue;
private String type;
private Products productList;
private String xmlProduct;
private final String SUCCESS = "success";
private final String FAIL = "fail";
private final int PRODUCT_PER_PAGE = 9;
private int page;
private InputStream result;
public SearchAction() {
}
public String execute() throws Exception {
System.out.println(searchValue);
productList = new Products();
ProductDAO dao = new ProductDAO();
productList = dao.searchProduct(searchValue, type);
if (productList.getProduct() == null) {
return FAIL;
}
page = (int) Math.ceil((float) productList.getProduct().size() / (float) PRODUCT_PER_PAGE);
xmlProduct = XMLUtilities.marshallJAXBToString(productList);
result = new ByteArrayInputStream(xmlProduct.getBytes("UTF-8"));
return SUCCESS;
}
public String getSearchValue() {
return searchValue;
}
public void setSearchValue(String searchValue) {
this.searchValue = searchValue;
}
public String getXmlProduct() {
return xmlProduct;
}
public void setXmlProduct(String xmlProduct) {
this.xmlProduct = xmlProduct;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public int getPage() {
return page;
}
public void setPage(int page) {
this.page = page;
}
public InputStream getResult() {
return result;
}
public void setResult(InputStream result) {
this.result = result;
}
}
and my jsp:
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<%#taglib uri="/struts-tags" prefix="s"%>
<%#taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%#taglib uri="http://java.sun.com/jsp/jstl/xml" prefix="x"%>
<%#taglib uri="/struts-tags" prefix="s"%>
<!DOCTYPE html>
<html>
<c:import charEncoding="UTF-8" var="productXSL" url="/XSL/product.xsl"/>
<s:set var="productXML" value="%{xmlProduct}" />
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="CSS/product.css">
<script src="JS/product.js"></script>
<script>
document.addEventListener("DOMContentLoaded", function () {
totalPage = <s:property value="%{page}"/>;
updatePagination(totalPage);
parseXML(<s:property value="%{result}"/>);
getData(1);
getXSL();
});
</script>
<s:set name="productType" value="%{type}"/>
<s:if test="%{#productType.equals('Helmet')}">
<title>Mũ bảo hiểm</title>
</s:if>
<s:if test="%{#productType.equals('Glove')}">
<title>Găng tay bảo hộ</title>
</s:if>
</head>
<body>
<div id="header" >
<s:if test="%{#productType.equals('Helmet')}">
<span id="headerTitle">Mũ bảo hiểm</span>
</s:if>
<s:if test="%{#productType.equals('Glove')}">
<span id="headerTitle">Găng tay bảo hộ</span>
</s:if>
</div>
<div id="searchZone">
<div id="wrap">
<form action="search">
<input id="searchValue" type="text" name="searchValue" value="<s:property value="%{searchValue}"/>" placeholder="Nhập sản phẩm bạn cần tìm kiếm"/>
<input type="hidden" name="type" value="<s:property value="#productType"/>" />
<input id="btnSearch" type="submit" value="Tìm kiếm" />
</form>
</div>
</div>
<div id="productList">
<x:transform xml="${productXML}" xslt="${productXSL}"/>
</div>
<div class="pagination">
<nav></nav>
</div>
</body>
I'm really new to these techinque and get stuck,
Maybe this methode can htlp you: How to pass InputStream value in Struts2 action class to ajax in jsp page and convert the value into Json Array
it's consite to use JSON Array.
good luck.

WebSocket not working in chat application?

This is my java class
public class ServerEndPointDemo
{
#OnOpen
public void handleOpen()
{
System.out.print("Connectin is created");
}
#OnMessage
public String handleMessage(String message)
{
System.out.print("message from Client = "+message);
String replyMessage = "echo"+message;
System.out.print("message send to Client = "+replyMessage);
return replyMessage;
}
#OnClose
public void handleClose()
{
System.out.print("Connectin is closed");
}
#OnError
public void handleError(Throwable e)
{
e.printStackTrace();
}
}
This is my jsp page
<!DOCTYPE html>
<html>
<head>
<title>WEB SOCKET 01</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
</head>
<body>
<form>
<input type="text" name="t1" id="textMessage">
<input type="button" value="SendMessage" onclick="sendMessage()" >
</form>
<textarea rows="10" cols="20" id="messagesTextArea"></textarea>
<script type="text/javascript" language="javascript">
var messagesTextArea = document.getElementById("messagesTextArea");
var textMessage = document.getElementById("textMessage");
var webSocket = new webSocket("ws://localhost:8080/WebSocketPrj01/ServerEndPointDemo");
webSocket.Onopen = function Message(){processOpen(message);};
webSocket.Onmessage = function Message(){processMessage(message);};
webSocket.Onclose = function Message(){processClose(message);};
webSocket.Onerror = function Message(){processError(message);};
function processOpen(message)
{
messagesTextArea.value +="server Connected....."+"\n";
}
function processMessage(message)
{
messagesTextArea.value +="Receive from server....."+message.data+"\n";
}
function processClose(message)
{
webSocket.send("client disconnected");
messagesTextArea.value +="server DISConnected....."+"\n";
}
function sendMessage()
{
alert("enter");
if(textMessage.value!=="close")
{
alert(textMessage.value);
webSocket.send(textMessage.value);
alert("2");
messagesTextArea.value +="send to server....."+textMessage.value()+"\n";
alert("3");
textMessage.value="";
alert("4");
}
else{
alert("else message");
webSocket.close();
}
}
function processError(message)
{
webSocket.send("client disconnected");
messagesTextArea.value +="error....."+"\n";
}
</script>
</body>
</html>
This line is not working webSocket.send(textMessage.value);
Also I am getting this error on console while inspecting element
TypeError: webSocket is not a constructor newjsp.jsp:25.
TypeError: webSocket is undefined
It should be:
var webSocket = new WebSocket("ws://localhost:8080/WebSocketPrj01/ServerEndPointDemo");
("WebSocket" starting with capital letter).

Populate html table data based on dropdown list using jQuery and Java

<%# 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">
<%#taglib uri="/struts-tags" prefix="s"%>
<%# taglib prefix="sj" uri="/struts-jquery-tags"%>
<jsp:include page="checkLogin.jsp" />
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Allocate Tans</title>
<script type="javascript" src="jquery-1.7.js"></script>
<sj:head jqueryui="true" jquerytheme="cupertino" />
</head>
<script type="text/javascript">
$(document).ready(function()
{
$('#batchID').change(function(event) {
var batch=$('#batchID').val();
$.ajax({
url : "doShowAllocationStatus.action",
data : "batch="+batch,
success : function(html) {
$('#table').html(html);
},
error : function(html) {
alert("error");
}
});
});
});
</script>
<body>
<div id=table>
<s:form action="doAllocate" name="allocate" executeResult="true">
<s:actionerror />
<s:actionmessage />
<s:select label="Select Batch" headerKey="-1"
headerValue="Select a Batch..." list="%{#session.Batchs}"
Value="batch" name="batch" id="batchID" />
<s:select label="Select User" headerKey="-1"
headerValue="Select an User..." list="%{#session.users}" name="user"
value="user" />
<s:radio list="#{'Curator':'Curator','QC':'QC'}" name="user_work_as" />
<s:submit value="Allocate" id="AllocateID" />
<table align="center" border="2" width="800">
<tr>
<th>TAN</th>
<th>Curator</th>
<th>Curator Status</th>
<th>QC</th>
<th>QC Status</th>
</tr>
<s:iterator value="allocationList" var="tableID">
<tr>
<td><s:checkbox name="Tans" fieldValue="%{#tableID.tan}"
theme="simple" />
<s:property value="tan" /></td>
<td><s:property value="curator" /></td>
<td><s:property value="curator_status" /></td>
<td><s:property value="qc" /></td>
<td><s:property value="qc_status" /></td>
</tr>
</s:iterator>
</table>
</s:form>
</div>
</body>
</html>
In this when I use the for all content inside the dropdown select works fine as i expected for dropdown list and table but it react different I mean the table is appended with same rows once again when I submit and if I select some thing in batch dropdown list then the table comes to it correct list. If I used only for table, it prints the full page once again. I can understand what had happen, but could not find solution to achieve what I need.
My aim is to display the table based on the batch selected and the submit should do what it actually has to do.
server side code...
package controller;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import model.BatchInfo;
import model.CationDAO;
//import org.apache.struts2.interceptor.SessionAware;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
#SuppressWarnings("serial")
public class AllocateTAN extends ActionSupport {
//Fields that hold data...
private List<BatchInfo> allocationList =new ArrayList<BatchInfo>();
private String batch;
private List<String> batchs = new ArrayList<String>();
private String TAN;
private String Tans[];
private String user;
private List<String> users = new ArrayList<String>();
private String user_work_as;
//getters and setters....
public List<BatchInfo> getAllocationList() {
return allocationList;
}
public void setAllocationList(List<BatchInfo> allocationList) {
this.allocationList = allocationList;
}
//#RequiredStringValidator(message = "Batch Not Selected")
public String getBatch() {
return batch;
}
public void setBatch(String batch) {
this.batch = batch;
}
public List<String> getBatchs() {
return batchs;
}
public void setBatchs(List<String> batchs) {
this.batchs = batchs;
}
//#RequiredStringValidator(message = "TAN Not Selected")
public String getTAN() {
return TAN;
}
public void setTAN(String tAN) {
TAN = tAN;
}
public String[] getTans() {
return Tans;
}
public void setTans(String[] tans) {
Tans = tans;
}
//#RequiredStringValidator(message = "Worker Not Selected")
public String getUser() {
return user;
}
public void setUser(String user) {
this.user = user;
}
public List<String> getUsers() {
return users;
}
public void setUsers(List<String> users) {
this.users = users;
}
//#RequiredStringValidator(message = "Select Any One")
public String getUser_work_as() {
return user_work_as;
}
public void setUser_work_as(String user_work_as) {
this.user_work_as = user_work_as;
}
//variable used to access DataBase...
CationDAO dao1 = new CationDAO() ;
//flow 1.: making all details available for the allocate TAN page...when page page is loaded 1st time
public String AllocatingTANpageDetails() throws SQLException{
Map<String, Object>session=ActionContext.getContext().getSession();
this.batchs=dao1.Batch_List();
session.put("Batchs", batchs);
//Tans=dao1.Tan_list(getBatch());
this.users=dao1.Users_List();
session.put("users", users);
return SUCCESS;
}
/*TAN list
private void showTANlist(String Batch1) throws SQLException{
Map<String, Object>session=ActionContext.getContext().getSession();
Tans=dao1.Tan_list(Batch1);
session.put("Tans", Tans);
}*/
//flow 2.: showing Allocation Status in Table form...in same page
public String showAllocationStatus() throws SQLException {
System.out.println("Inside Show Allocation Status");
if(batch==null||"-1".equals(batch)){
addActionMessage("Please!... Select a Batch");
return ERROR;
}
Map<String, Object>session=ActionContext.getContext().getSession();
//setBatch(batch_value);
String bth=getBatch();
if (bth==null || bth=="-1"){
System.out.println("batch is empty "+bth);
}
System.out.println(bth);
session.put("Batch",bth);
// showTANlist(bth);
System.out.println("Processing Allocation List... ");
this.allocationList=(List<BatchInfo>)dao1.status(bth);
System.out.println(allocationList);
session.put("AllocationList",allocationList);
System.out.println("Finished...");
return SUCCESS;
}
//execute method form allocating a TAN for a user...
public String execute(){
String statusTable=null;
String er = null;
if(Tans==null||"-1".equals(Tans)){
addActionError("Please!... Select a TAN"); er="er";
}
if (user==null||"-1".equals(user)){
addActionError("Please!... Select an Worker");er="er";
}
if (user_work_as==null||user_work_as==""||"-1".equals(user_work_as)){
addActionError("Please!... Select either Curation or QC");er="er";
}
try {
statusTable=showAllocationStatus();
} catch (SQLException e) {
e.printStackTrace();
}
if(!"er".equals(er)&& "success".equals(statusTable)){
System.out.println("inside Execute metho of AllocateTAN.java");
if ("QC".equalsIgnoreCase(user_work_as)){
try {
if(!"Complete".equalsIgnoreCase(dao1.CheckCurator(batch,Tans))){
addActionMessage("Curation Not yet completed");
return ERROR;
}
dao1.AllocateTANforUser( batch, Tans, user, user_work_as);
this.allocationList=(List<BatchInfo>)dao1.status(getBatch());
return SUCCESS;
} catch (SQLException e) {
e.printStackTrace();
}
}else if("Curator".equalsIgnoreCase(user_work_as)){
try {
dao1.AllocateTANforUser( batch, Tans, user, user_work_as);
} catch (SQLException e) {
e.printStackTrace();
}
this.allocationList=(List<BatchInfo>)dao1.status(getBatch());
return SUCCESS;
}
}
return ERROR;
}
}
First, I would suggest that you change your structure as you are using AJAX hardly at all (you only use one on load and that's it, and that is not different than passing all those values from the very beginning from the action). As you only have 3 values to pass, is fairly easy to capture them with jQuery("#myid").val() and pass them with jQuery.ajax. something like
<s:button value="Allocate Me!!!" onclick="allocating_you()"/>
and then
function allocationg_you(){
var val1 = jQuery("#value1").val();
var val2 = jQuery("#value2").val();
var val3 = jQuery("#value3").val();
jQuery.ajax({
url: "allocator",
data: "val1=" + val1 +"&val2=" + val2 + "&val3=" + val3 + "&r=" //dont forget to add a random number
success: function(data){
jQuery("#mytable").html(data).load();
}
});
}
finally, you should reduce the ajax refreshment to the minimun necessary, as it will be easier to mantain and to give aesthetics. so for example your template should be divided like this
<your form>
<your table header>
<div id="mytable">
with this template you would only have to refresh the actual content and everything else will remain intact (true AJAX), so in your JSP response for your AJAX call there should be only the iterator part. you will even be able to create the table with a scrollbar and a static header, only needing to put some matching sizes in your ajax cells along with the table tag.
Hope this helps you. If you manage to crack this you will be able to do wonders. jQuery + Struts2 + (seems that you are not using Hbernate, but oh well) it's a monstrous combination.

How to access web service from a stand alone html file?

i'm new in a web service. i'm trying to make a simple web service REST on java for a simple login application.. here's my code:
Server side:
package com.testingws.webservices;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
#Path("/login/{username}/{password}/{datetime}")
public class webServicesClass {
#GET // this method process GET request from client
#Produces("application/json") // sends JSON
public String getJson( #PathParam("username") String username, #PathParam("password") String password) { // empno represents the empno sent from client
if (username.equalsIgnoreCase("admin") && password.equalsIgnoreCase("admin")){
return "{'loginstatus':'success'}";
}
else{
return "{'loginstatus':'failed'}";
}
} // end of
}
Client side :
<!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>Client Login</title>
<script type="text/javascript">
function loginProcess(){
var tempUser = document.getElementById("loginUsername");
var tempPass = document.getElementById("loginPassword");
var dateTime = new Date();
var url = "http://localhost:8181/TestWSProject/authentication/login/" + tempUser.value + "/" + tempPass.value + "/" + dateTime.toUTCString();
var xmlhttp = new XMLHttpRequest(); //#slaks: i put it here
xmlhttp.open('GET',url,true);
xmlhttp.send(null);
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4) {
if ( xmlhttp.status == 200) {
var det = eval( "(" + xmlhttp.responseText + ")");
//alert(det.loginstatus);
if(det.loginstatus=="success")
{
setCookie("login", "yes", 1);
window.location="main.html";
}
else
{
alert("incorrect username or password");
}
}
else
alert("Error ->" + xmlhttp.status + xmlhttp.responseText);
}
}
}
function getCookie(c_name)
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
{
x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
x=x.replace(/^\s+|\s+$/g,"");
if (x==c_name)
{
return unescape(y);
}
}
}
function setCookie(c_name,value,exdays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value;
}
function checkCookie()
{
var loginStatus=getCookie("login");
//alert(loginStatus);
if (loginStatus=="yes")
{
//alert("Masuk pengecekan")
window.location="main.html";
}
}
</script>
</head>
<body onload="checkCookie()">
<h2>LOGIN FORM</h2>
<BR>
Username : <input type="text" id="loginUsername"/>
<BR>
Password : <input type="password" id="loginPassword"/>
<BR>
<input type="button" value="Login" onclick="loginProcess()"/>
</body>
</html>
when i access my client from webContent url (http://localhost/TestWSProject/index.html) that service works perfectly, but if i access my client from stand alone HTML file (file:///D:/+Prog/webservice/TestWSProject/WebContent/index.html) it give me xmlHTTPStatus = 0 and that service is not works.. any solution for this problem?? really thanks..
Some browsers have security restrictions which restrict files from performing certain actions if they are being accessed directly from the file system.
This could be what is causing the error.

Javabeans with jsp:useBean. How do they work? I don't understand

I have to get 2 numbers and an operation from a jsp file, using a java bean. After submitting the numbers, take them to a servlet from that Java Bean and return an result of them. Problem is that the java bean fields are never completed with the numbers written in textboxes.
So, I have, index.jsp's body:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<link rel="stylesheet" type="text/css" href="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 class ="button" TYPE="submit" NAME="actiune" VALUE="Calculate"/>
</FORM>
<jsp:useBean id="binOp" class="beans.BinaryOperation" scope="session"/>
<jsp:setProperty name="binOp" property="*"/>
</body>
The servlet's processRequest method, Controller.java, placed in package servlets:
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();
}
}
And the bean, BinaryOperation, placed in package beans:
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)));
}
}
In the Apache log I have next output from the if statement(see the servlet - System.out.println(binOp.getNr1() + binOp.getNr2() + binOp.getOp());):
nullnullnull
Where is my mistake?
The bean is only a Java class for hodling properites with getters and setters. It does not have any magic properties and does not fill itself. It just a type of object, like a pattern. This is how they work. You must manually fill the properties you want with the appopriate setSmth method.
I've did one more jsp file between index.jsp and Servlet:
<jsp:useBean id="binOp" class="beans.BinaryOperation" scope="session"/>
<jsp:setProperty name="binOp" property="*"/>.
This did the "magic".

Categories