What is needed to start a web-based project?

  • Thread starter Roger Helliwell
  • Start date
R

Roger Helliwell

Hello Java Experts,

I've been using Java to write stand alone apps for a number of months.
I have now been asked to create a web-based solution, but having no
web-programming experience, the task seems daunting. I bought myself a
book on JSP and thought that would be the ticket -- but, umm, no.

So were does one "start"? All the online tutorials I've read so far,
explain the details but not the general idea. Can I still use eclipse
to compile Jsp files, or will I need something else?

What do I need to write an app that runs on a web-server, takes a text
file that a web-user has submitted, processes it (this I can do), and
sends the results back to the client? I do have HTML and some
javascripting knowledge, but just stuck on how the pieces go together.
(What should run on the server, what runs on the client etc.)

Thanks,
Roger
 
A

Andrew Thompson

"Roger Helliwell" ...
Hello Java Experts,

Given that salutation, I should probably
not respond. I have only just dipped my
toe into J2EE. (and am no expert on the
J2SE!)

But (shrugs) what the hey.
I've been using Java to write stand alone apps for a number of months.
I have now been asked to create a web-based solution, but having no
web-programming experience, the task seems daunting. I bought myself a
book on JSP and thought that would be the ticket -- but, umm, no.

So were does one "start"? All the online tutorials I've read so far,
explain the details but not the general idea. Can I still use eclipse
to compile Jsp files, or will I need something else?

Install Apache/Tomcat on your system,
JSP's will be compiled the first time they
are called (you open the .jsp file from
'localhost')
What do I need to write an app that runs on a web-server, takes a text
file that a web-user has submitted, processes it (this I can do), and
sends the results back to the client?

Heck, it sounds like you are almost there.

Is it _only_ the 'data back to client' you are
having trouble with? Or are you also trying
to figure how to convert the earlier bits
to use .jsp as well?
..I do have HTML and some
javascripting knowledge, but just stuck on how the pieces go together.
(What should run on the server, what runs on the client etc.)

You can write a lot of webapps where the
only thing the client sees is html. This is
one of the things that got me into server side
stuff as I want to be able to cater to anyone
with a browser that understands html, which
is a much wider user base than UA's with
'a current Java' installed..

HTH
 
R

Roger Helliwell

Heck, it sounds like you are almost there.

Is it _only_ the 'data back to client' you are
having trouble with? Or are you also trying
to figure how to convert the earlier bits
to use .jsp as well?

Say a web-user is presented with a form to enter a file name with a
"Submit" button (ie. imagine attaching a file to an e-mail). How would
the server accept the file for processing? This couldn't be javascript
since I always thought js didn't have client-side file functionality.

Roger
 
A

Andrew Thompson

Roger said:
...
Say a web-user is presented with a form to enter a file name with a
"Submit" button (ie. imagine attaching a file to an e-mail). How would
the server accept the file for processing? This couldn't be javascript
since I always thought js didn't have client-side file functionality.

No, I do not think this can be done in JS,
certainly not client-side JS.

As far as file _uploads_ go, I would have
to cede to others, it is something I have
been meaning to look into.

But (scratches head) what you are asking now
does not gel with your earlier comment. I
understood from your initial statement..

<this I can do>
write an app
take a text file
process it
</this I can do>

Did I misunderstand you?
 
K

KC Wong

Say a web-user is presented with a form to enter a file name with a
"Submit" button (ie. imagine attaching a file to an e-mail). How would
the server accept the file for processing? This couldn't be javascript
since I always thought js didn't have client-side file functionality.

Uploading file... that's not the first step if you're new to webapps.

Do you understand how to do this?
User fills data in a HTML form retrieved from server, submit it, then server
receives the response, validates it (prompts user to re-enter on error) and
stores the data in a file on the server or in database.

If yes:
Take a look at Oreilly's servlet package
(http://www.servlets.com/cos/index.html). It has a multipart parser which
makes uploading files easy as pie. You can't use it for commercial projects
though.

If not:
Then you need to start from the basics first. I'll post more if you need
them - just ask!


HTH,

KC
 
R

Ryan Stewart

*snip*
As far as file _uploads_ go, I would have
to cede to others, it is something I have
been meaning to look into.
*more snip*

See http://www.servlets.com/cos/index.html as suggested by KC Wong.
Specifically pay attention to the MultipartRequest. Using that with a <input
type="file" ... > tag, you can write a quick and dirty file upload JSP in
about a dozen lines.
 
R

Roger Helliwell

Uploading file... that's not the first step if you're new to webapps.

Do you understand how to do this?
User fills data in a HTML form retrieved from server, submit it, then server
receives the response, validates it (prompts user to re-enter on error) and
stores the data in a file on the server or in database.

If yes:
Take a look at Oreilly's servlet package
(http://www.servlets.com/cos/index.html). It has a multipart parser which
makes uploading files easy as pie. You can't use it for commercial projects
though.

If not:
Then you need to start from the basics first. I'll post more if you need
them - just ask!

I'm afraid it's the latter. I'm in a situation like you've mentioned--
I've got a server-side app that simply processes text files, and it's
just waiting for a web-user to press a "Submit" button to send the
file.

Thanks for the link, it's one I haven't discovered yet, and looks
promising.

Roger
 
K

KC Wong

Hello Roger,
I'm afraid it's the latter. I'm in a situation like you've mentioned--
I've got a server-side app that simply processes text files, and it's
just waiting for a web-user to press a "Submit" button to send the
file.

Test and play around with this example...

test.jsp

<%
String username = "";
String hiddenValue = "abc";
boolean posted = false;

if ("post".equalsIgnoreCase(request.getMethod())) {
posted = true;
username = String.valueOf(request.getParameter("username"));
hiddenValue = String.valueOf(request.getParameter("hiddenValue"));
%>
You submitted these data:
<%
}
%><html>
<body>
<form name="testForm" action="test.jsp" method="post">
Username: <input type="text" name="username" value="<%= username %>"><br/>
<%= (posted)? "Hidden Value: " : "" %><input type="<%= (posted)? "text" :
"hidden" %>" name="hiddenValue" value="<%= hiddenValue %>">
<%
if (!posted) {
%>
<input type="submit" value="Submit Form"/>
<%
}
%>
</form>
</body>
</html>

Put this JSP in your webapp directory, open it with browser and see what
happens.
It is a simple example of:
- Dynamically generate form from server
- Submit data from client
- Process data on server side
- Generate report to client


This is an file-upload example using the Oreilly servlet package.

<%@page contentType="text/html; charset=UTF-8"
%><%@page import="com.oreilly.servlet.*, com.oreilly.servlet.multipart.*"
%><%@page import="java.io.*, java.util.*"
%><%
try {
if ("POST".equalsIgnoreCase(request.getMethod())) {
// Handle upload
MultipartRequest mr = new MultipartRequest();
mr.startUpload(request, "C:\\", "Test_");

Enumeration e = mr.getFileNames();
while (e.hasMoreElements()) {
//
String id = String.valueOf(e.nextElement());
File f = mr.getFile(id);
%>
File ID : <%= id %><br/>
Filename : <%= mr.getRealName(id) %><br/>
MIME Type: <%= mr.getContentType(id) %><br/>
<%
}
}
} catch (Exception ex) {
%>
Error Message: <%= ex.getMessage() %><br/>
<%
}
%><html>
<head>
</head>
<body>
<form enctype="multipart/form-data" action="test.jsp" method="POST">
Upload File: <input type="file" name="myFile1"><br/>
<input type="submit" value="Upload">
</form>
</body>
</html>

The trigger is the line: mr.startUpload(...).
The file will be uploaded from the client to your server's C:\.

Make sure you read the API documentation of the Oreilly servlet package!


HTH,

KC
 
J

JayDay

Roger Helliwell said:
I've been using Java to write stand alone apps for a number of months.
I have now been asked to create a web-based solution, but having no
web-programming experience, the task seems daunting. I bought myself a
book on JSP and thought that would be the ticket -- but, umm, no.

Hi,

I already installed TomCat for some other projects, but I only used
servlets. Then it took me 1 day to learn JSP and create a simple interface
to my java program. I'm not a genius, so it cant be very difficult.

sptest
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top