DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

The Latest Data Topics

article thumbnail
Building a REST Service That Collects HTML Form Data Using Netbeans, Jersey, Apache Tomcat, and Java
The Jersey project is very well documented so it makes it easy to learn REST with Java. In this article I’m going to build two projects. The first project will be a very simple HTML page that presents a form to the user and then submits it to a REST project residing on the same server. The second project will be the REST part. For this article I used the following tools: 1. Netbeans 7 2. Apache Tomcat 7 3. Jersey 4. Java I built this on OS X Lion. Go ahead and create a new Maven Web Application with Netbeans 7 called: MyForm Once the project has been generated take the resulting (default) index.jsp file and delete it. In its place add a file called: index.html and add the following content to it: Name: Message: Item 1: Item 2: Basically, I created a simple (ugly) form that takes a few parameters the user enters. They submit the form and the data is sent to the REST project we will soon be building. The idea here is we are using an HTTP POST to create a new message. That’s it for the first project! With Netbean’s Maven integration do a Clean and Build and then deploy the resulting WAR file to Apache Tomcat. Create another new Maven Web Application with Netbeans 7 called: RESTwithForms Add two new Java classes to the new project: 1. MyApplication 2. MessageResource The code for MyApplication.java is as follows: package com.giantflyingsaucer; import com.sun.jersey.api.core.PackagesResourceConfig; import javax.ws.rs.ApplicationPath; @ApplicationPath("/") public class MyApplication extends PackagesResourceConfig { public MyApplication() { super("com.giantflyingsaucer"); } } In a brief nutshell this code allows us to make use of some Servlet 3.0 goodies (we don’t need to create a web.xml file for this project as an example). For more details see the sections titled: Example 2.8. Reusing Jersey implementation in your custom application model and Example 2.9. Deployment of a JAX-RS application using @ApplicationPath with Servlet 3.0 at this link. The real guts of the REST project are in the MessageResource.java file as seen below: package com.giantflyingsaucer; import java.net.URI; import java.util.List; import java.util.UUID; import javax.ws.rs.FormParam; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.core.Response; import javax.ws.rs.Consumes; import javax.ws.rs.core.MediaType; @Path("/messages") public class MessageResource { @POST @Consumes(MediaType.APPLICATION_FORM_URLENCODED) public Response createMessage(@FormParam("name") String name, @FormParam("message") String message, @FormParam("thelist") List list) { if(name.trim().length() > 0 && message.trim().length() > 0 && !list.isEmpty()) { // Note 1: Normally you would persist the new message to a datastore // of some sort. I'm going to pretend I've done that and // use a unique id for it that obviously points to nothing in // this case. // Note 2: The way I'm returning the data should be more like the commented // out piece, I am being verbose for the sake of showing you how to // get the values and show that it was read. return Response.created(URI.create("/messages/" + String.valueOf(UUID.randomUUID()))).entity( name+ ": " + message + " --> the items: " + list.get(0) + " - " + list.get(1)).build(); // This is a more real world "return" //return Response.created(URI.create("/messages/" + String.valueOf(UUID.randomUUID()))).build(); } return Response.status(Response.Status.PRECONDITION_FAILED).build(); } } Note: Pay special attention to the comments. Please don’t email me stating I shouldn’t be returning text back with the values, also please don’t tell me I should be iterating the list, etc. this is just a demo. You will obviously do this differently in a production environment. The key here is simplicity and minimal code. At this point you need to add jersey-server as a dependency in your POM file. com.sun.jersey jersey-server-linking 1.9.1 With Netbean’s Maven integration do a Clean and Build and then deploy the resulting WAR file to Apache Tomcat. You are now ready to test it out. Load up the HTML file from the first project and enter some data and then submit it. If you have a tool like FireBug for Firefox, you can also see that an HTTP 201 was returned (if successful). If you don’t enter any data in the form then you should get an HTTP 412 back. With not much more work you could just as easily use something like jQuery and submit the form via AJAX.
July 13, 2022
by Chad Lung
· 66,985 Views · 4 Likes
article thumbnail
Reaper 3.0 for Apache Cassandra Is Available
The K8ssandra team is pleased to announce the release of Reaper 3.1. Let’s dive into the features and improvements that 3.0 recently introduced.
July 13, 2022
by Alexander Dejanovski
· 6,418 Views · 1 Like
article thumbnail
Everything You Need to Know About SaaS Security Certification
We'll talk about the significance of SaaS security certifications, the many sorts available, and how to pick which one is appropriate for your organization.
July 12, 2022
by Varsha Paul
· 6,085 Views · 2 Likes
article thumbnail
Overcoming Challenges in End-To-End Microservices Testing
In this guide, we will address critical challenges in end-to-end microservices testing and how you can solve them by staying in sync.
July 12, 2022
by Vivek Mannotra
· 7,857 Views · 2 Likes
article thumbnail
Securing Kubernetes Secrets With HashiCorp Vault
Secrets in Kubernetes are used to store sensitive information. This article will show how to secure Kubernetes secrets using Hashicorp Vault.
July 12, 2022
by Nikhil Purva
· 7,027 Views · 2 Likes
article thumbnail
The State of Kubernetes Stateful Workloads at DreamWorks
Learn how DreamWorks is running 370 databases on 1200+ Kubernetes pods.
July 11, 2022
by Sylvain Kalache
· 5,368 Views · 1 Like
article thumbnail
How Developers Need to Choose the Right Database for React Native App
React Native has become the most well-known name for creating complex hybrid apps that deliver a natural user experience.
July 11, 2022
by Bharat Ghode
· 5,491 Views · 2 Likes
article thumbnail
MongoDB vs. DynamoDB Head-to-Head: Which Should You Choose?
We compare MongoDB and DynamoDB, their pros and cons, data types, cost, reliability, performance and security.
Updated July 11, 2022
by Shawn Adams
· 6,634 Views · 3 Likes
article thumbnail
How Can You Benefit from Containerized Microservices?
How can microservices benefit from containerization technology? This article covers runtime options, security, isolation, service discovery, and more.
July 10, 2022
by Hiren Dhaduk
· 7,939 Views · 4 Likes
article thumbnail
Building an IoT Security Camera With Raspberry Pi and Render
How To Create Your Own Security Camera System With Raspberry Pi, Picamera2, Flask, and Render
July 10, 2022
by Luca Cipriani
· 9,084 Views · 3 Likes
article thumbnail
How to Build a Full-Stack App With Next.js, Prisma, Postgres, and Fastify
In this article, we’ll learn how to build a Full-stack application using Next.js, Prisma, Postgres, and Fastify.
July 10, 2022
by Clara Ekekenta
· 15,144 Views · 5 Likes
article thumbnail
Reading and Writing With a ConcurrentHashMap
Get up to speed with concurrent writes with ConcurrentHashMap.
July 10, 2022
by Dan Newton
· 9,245 Views · 3 Likes
article thumbnail
Apache BookKeeper: What Makes A Qualified Storage System for Apache Pulsar
Understand the secrets behind Apache Pulsar's storage layer.
July 9, 2022
by Sherlock Xu
· 7,943 Views · 4 Likes
article thumbnail
Learn Microservices With Coding Over Cocktails
If you’re curious to learn more about microservices, then you’ve come to the right place!
July 9, 2022
by David Brown DZone Core CORE
· 8,535 Views · 5 Likes
article thumbnail
Release Management for Microservices: Multi vs. Monorepos
Evaluate the differences between multi and monorepo deployments for microservice applications.
July 9, 2022
by Tomas Fernandez
· 9,116 Views · 2 Likes
article thumbnail
Building a Better Notification System [Video]
This video will really give you enough to get started thinking about what improvements you might want to make to your notification infrastructure or what notifications you want to send that you’re not sending today and how you should think about building and maintaining those systems moving forward.
Updated July 8, 2022
by Troy Goode
· 12,569 Views · 4 Likes
article thumbnail
Common Table Expression in ClickHouse
What is Common Table Expression(CTE)? In this post, learn how to use CTE in the ClickHouse database and follow along with use cases with examples.
July 8, 2022
by Taras Baranyuk DZone Core CORE
· 10,034 Views · 8 Likes
article thumbnail
Getting Ready for Microservices
The journey to microservices is an epic one. But it can be made easier by preparing your monolith for the transition. Here are a few tips to get you going.
July 8, 2022
by Tomas Fernandez
· 7,434 Views · 6 Likes
article thumbnail
Optimizing Firmware: The Key to Shipping IoT Devices on Time
Managing the many discrete steps from IoT product idea to launch can lead to shipping delays. Here are some tips to help you optimize the development process.
July 8, 2022
by François Baldassari
· 9,121 Views · 1 Like
article thumbnail
AI in Cybersecurity: An Overview
Artificial Intelligence has become pivotal in simulating human intelligence and has immense potential in Cybersecurity. IoT will further densify the attack.
July 8, 2022
by Lucia Adams
· 8,752 Views · 3 Likes
  • Previous
  • ...
  • 202
  • 203
  • 204
  • 205
  • 206
  • 207
  • 208
  • 209
  • 210
  • 211
  • ...
  • Next
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook
×