Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7744361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:44:57+00:00 2026-06-01T09:44:57+00:00

As total clojure noob, I am trying to start one small tutorial app, in

  • 0

As total clojure noob, I am trying to start one small tutorial app, in order to get familiar with compojure. It’s a small application which lets user add two numbers, and after clicking on button displays their sum on the other page. I followed instruction from Mark McGranaghan blog. Everything seems ok, until I try to get sum of two numbers I have entered, instead of getting result, I am redirected to the same page (so basically I am stuck on first step of this tutorial). After checking the code, it seems that NumberFormatException is triggered when input parsing takes place (for some reason). In all my tests, I have tried to input all kinds of number format , but with no success. Here is the simplest code version , for which author said should work (I have tried the latest version from github site– same scenario: NFE):

    (ns adder.core
  (:use compojure.core)
  (:use hiccup.core)
  (:use hiccup.page-helpers))

(defn view-layout [& content]
  (html
    (doctype :xhtml-strict)
    (xhtml-tag "en"
      [:head
        [:meta {:http-equiv "Content-type"
                :content "text/html; charset=utf-8"}]
        [:title "adder"]]
      [:body content])))

(defn view-input []
  (view-layout
    [:h2 "add two numbers"]
    [:form {:method "post" :action "/"}
      [:input.math {:type "text" :name "a"}] [:span.math " + "]
      [:input.math {:type "text" :name "b"}] [:br]
      [:input.action {:type "submit" :value "add"}]]))

(defn view-output [a b sum]
  (view-layout
    [:h2 "two numbers added"]
    [:p.math a " + " b " = " sum]
    [:a.action {:href "/"} "add more numbers"]))

(defn parse-input [a b] ;; this is the place where problem occures
  [(Integer/parseInt a) (Integer/parseInt b)])

(defroutes app
  (GET "/" []
    (view-input))

  (POST "/" [a b]
    (let [[a b] (parse-input a b)
          sum   (+ a b)]
      (view-output a b sum)))

Can anyone tell me better way to pars the input values, in order to avoid this exception?I have tried couple of techniques , but nothing worked for me. I am using Leningen v1.7.1 with clojure 1.3 on win 7 machine.

Here is content of my project.clj file:

(defproject adder "0.0.1"
  :description "Add two numbers."
  :dependencies
    [[org.clojure/clojure "1.3.0"]
     [org.clojure/clojure-contrib "1.1.0"]
     [ring/ring-core "1.0.2"]
     [ring/ring-devel "1.0.2"]
     [ring/ring-jetty-adapter "1.0.2"]
     [compojure "1.0.1"]
     [hiccup "0.3.8"]]
  :dev-dependencies
    [[lein-run "1.0.0"]])

and run.clj script:

(use 'ring.adapter.jetty)
(require 'adder.core)

(let [port (Integer/parseInt (get (System/getenv) "PORT" "8080"))]
  (run-jetty #'adder.core/app {:port port}))

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T09:44:58+00:00Added an answer on June 1, 2026 at 9:44 am

    You are using compojure 1.0.1, the example in the blog you are following is using compojure 0.4.0.

    As of version 0.6.0, Compojure no longer adds default middleware to routes. This means you must explicitly add the wrap-params and wrap-cookies middleware to your routes.

    Source: https://github.com/weavejester/compojure

    So you need to explicitly add the wrap-params middleware. So the following changes are required…

    (ns adder.core
      (:use                    ; change to idiomatic usage of :use
        [compojure.core] 
        [hiccup.core]
        [hiccup.page-helpers]
        [ring.middleware.params :only [wrap-params]])) ; add middleware for params
    
    (defn view-layout [& content]
      (html
        (doctype :xhtml-strict)
        (xhtml-tag "en"
              [:head
               [:meta {:http-equiv "Content-type"
                       :content "text/html; charset=utf-8"}]
               [:title "adder"]]
              [:body content])))
    
    (defn view-input []
        (view-layout
         [:h2 "add two numbers"]
         [:form {:method "post" :action "/"}
         [:input.math {:type "text" :name "a" :id "a"}] [:span.math " + "]
         [:input.math {:type "text" :name "b" :id "a"}] [:br]
         [:input.action {:type "submit" :value "add"}]]))
    
    (defn view-output [a b sum]
      (view-layout
       [:h2 "two numbers added"]
       [:p.math a " + " b " = " sum]
       [:a.action {:href "/"} "add more numbers"]))
    
    (defn parse-input [a b]
      [(Integer/parseInt a) (Integer/parseInt b)])
    
    (defroutes main-routes             ; needs to be renamed
       (GET "/" []
          (view-input))
    
       (POST "/" [a b]
          (let [[a b] (parse-input a b)
              sum   (+ a b)]
          (view-output a b sum))))
    
    (def app (wrap-params main-routes)) ; wrap the params to allow destructuring to work
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

total nubi here and i'm trying to writ an application that trackes how far
total noob here. I've an array which looks like: Array ( [15] => Array
Total noob question. I am building a simple photoblog in Rails which consists of
Total newbie here, please bear with me. Building a very small personal app that
total noob to rails and am using the Hartl tutorial. Got to chapter 4
Total noob to anything lower-level than Java, diving into iPhone audio, and realing from
Total noob question, but here. CSS .product__specfield_8_arrow { /*background-image:url(../../upload/orng_bg_arrow.png); background-repeat:no-repeat;*/ background-color:#fc0; width:50px !important; height:33px
I followed this guide: http://wiki.unto.net/setting-up-clojure-and-slime Which walked me through the steps of building Clojure
Total noob question here, but not finding the answer via search. What is the
How would I get total CPU Usage from Windows Command Prompt?: Expected Output: 27%

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.