Organizational Research By

Surprising Reserch Topic

struts2 input result how does it work how are conversion validation errors h

struts2 input result how does it work how are conversion validation errors h  using -'java,validation,struts2,casting,type-conversion'

Main Question

The work flow should be like this: if an String is entered other than a number, first it should pass through a exception interceptor, and when passing through param interceptor, while converting to int type, it wont be able to do it using Integer.parseInt and an exception would occur; shouldn't that exception (that is NumberFormatException) be pushed into Value Stack ? Why does it not show NumberFormatException and show the result even though result should not be printed instead ?

Side Question

Whenever I add an alphabet in the form, it changed to zero...? Why so ?


<%@ taglib uri="/struts-tags" prefix="s"%>
<s:form action="divide">
    <s:textfield name="number1" label="number1"/>
    <s:textfield name="number2" label="number2"/>
    <s:submit value="divide"/>

package actions;

public class divide {
    int number1,number2,result;
    public String execute() throws Exception
        return "success";
    public int getNumber1() {
        return number1;
    public void setNumber1(int number1) {
        this.number1 = number1;
    public int getNumber2() {
        return number2;
    public void setNumber2(int number2) {
        this.number2 = number2;
    public int getResult() {
        return result;



<%@taglib uri="/struts-tags" prefix="s" %>
    the result of division is
    <s:property value="result"/>
<jsp:include page="index.jsp"></jsp:include>

handler jsp

<%@taglib uri="/struts-tags" prefix="s"%>
    following exception occured during the processing
    <s:property value="exception"/>
<jsp:include page="index.jsp"/>


<?xml version="1.0" encoding="UTF-8"?>

    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
        <package name="yo" extends="struts-default">
            <action name="divide" class="actions.divide">
                <exception-mapping result="error" exception="Exception"/>
                <result name="success">/result.jsp</result>
                <result name="error">/handler.jsp</result>


asked Sep 22, 2015 by mca.agarwal
0 votes

Related Hot Questions

1 Answer

0 votes
answered Sep 22, 2015 by 20shahi