You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by James Rome <ja...@gmail.com> on 2008/06/12 21:16:40 UTC
Servlet navigation
I am doing a project for a class of HS teachers in July, to teach them
the wonders of Java and NetBeans. I designed a set of servlets to let
them manage student grades. I am having them design the basic HTML in
NVU, and put it into the try blocks of the NB-generated processRequest
servlets, and then put it into out.println("..."); blocks. I am using
Tomct.
I would use JSF myself, but I have no time to get into that, so I am
using forms and submit buttons to do the navigation.
So the first test is to see if the navigation works with the static HTML
servlet pages. When that works, I will put in the database queries. But
the navigation is not working for me. I changed the Project (classdata)
Run property in NB to point to login.
Here is the processRequest login code:
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet login</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1 style=\"color: rgb(0, 102, 0);\">"
+"Student Grade Manager Login</h1>"
+ "<form method=\"post\" action=\"dataSelection\"
name=\"login\">");
out.println("<h3>User Name: <input maxlength=\"40\" size=\"40\""
+ "name=\"name\"></h3><br>");
out.println("<h3>Password: <input maxlength=\"40\" size=\"40\""
+ "name=\"password\" type=\"password\"></h3>"
+ "<input name=\"Login\" value=\"Login\"
type=\"submit\"><br>");
out.println("</body>");
out.println("</html>"); } finally {
out.flush();
}
This displays, the debugger and html inspector show that it indeed calls
the servlet at classdata/dataSelection. Its processRequst code is:
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try
{
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet dataSelection</title>");
out.println("</head>");
out.println("<body>");
out.println(
"<h1 style=\"color: rgb(0, 102, 0);\">Student Grade
Data</h1>");
out.println("<hr style=\"width: 100%; height: 2px;\">");
out.println(
"<form method=\"post\" action=\"studentData\" name=\"User
Choice\">");
out.println("<h2>Student Data</h2>");
out.println("<h3>Student Name:<input text=\"\"
name=\"studentName\""
+ " type=\"\"></h3>");
out.println("<input name=\"nameSubmit\" value=\"Submit Name\""
+ " type=\"submit\">");
out.println("</form>");
out.println("<hr style=\"width: 100%; height: 2px;\">");
out.println("<h2>Class Data</h2>");
out.println(
"<form method=\"post\" action=\"classData\"
name=\"classData\">"
+ " <input name=\"classData\" value=\"Get Class Data\""
+ " type=\"submit\"></form>");
out.println("<hr style=\"width: 100%; height: 2px;\">");
out.println("<form method=\"post\" action=\"logout\""
+ " name=\"Student Logout\"><input name=\"logout\""
+ " value=\"Logout\" type=\"submit\"><br></form>");
out.println("</body>");
out.println("</html>");
}
finally
{
out.flush();
}
But nothing displays! The login screen remains displayed. The browser
page source is blank.
And an initial navigation to the dataSelection URL is also blank.
What am I missing????
Here is web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>login</servlet-name>
<servlet-class>ARC08.login</servlet-class>
</servlet>
<servlet>
<servlet-name>logout</servlet-name>
<servlet-class>ARC08.logout</servlet-class>
</servlet>
<servlet>
<servlet-name>classData</servlet-name>
<servlet-class>ARC08.classData</servlet-class>
</servlet>
<servlet>
<servlet-name>studentData</servlet-name>
<servlet-class>ARC08.studentData</servlet-class>
</servlet>
<servlet>
<servlet-name>dataSelection</servlet-name>
<servlet-class>ARC08.dataSelection</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>login</servlet-name>
<url-pattern>/login</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>logout</servlet-name>
<url-pattern>/logout</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>classData</servlet-name>
<url-pattern>/classData</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>studentData</servlet-name>
<url-pattern>/studentData</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>dataSelection</servlet-name>
<url-pattern>/dataSelection</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
</web-app>
There is nothing in the Tomcat log file, but the NetBeans console shows
Tomcat starting up OK.
Thanks for the help,
Jim
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Servlet navigation
Posted by Hassan Schroeder <ha...@gmail.com>.
On Thu, Jun 12, 2008 at 12:16 PM, James Rome <ja...@gmail.com> wrote:
> I am doing a project for a class of HS teachers in July, to teach them
> the wonders of Java and NetBeans. I designed a set of servlets to let
> them manage student grades. I am having them design the basic HTML in
> NVU, and put it into the try blocks of the NB-generated processRequest
> servlets, and then put it into out.println("..."); blocks.
ewwww. :-)
You do know that it's considered better practice to use a separate
view technology like JSP, Velocity, Flex, whatever for display and
servlets only as controllers, right?
Makes life (and debugging) a lot easier, too :-)
FWIW,
--
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org