2013年11月19日星期二

jsp http 404 error , try the method

N I do this for several days , the Internet, said something to solve a lot of problems , but the last question , the database is not connected .
I basically have put online can provide information about my reasons for this fault may have been tried , do not work , but unfortunately can only ask questions.

I want my various configuration details , listed below , hoping to understand friends can help me , thank you very much !

I use Myeclipse10 + tomcat6 + mysql

I think the function is very simple , is to fill out a registration page jsp . The data is then stored to the database. It's that simple

static jsp pages can be opened , but once I clicked submit , the will at http 404 error not available

This is the situation to start tomcat6

November 17 , 2013 10:31:17 PM org.apache.catalina.core.AprLifecycleListener init
INFO: Loaded APR based Apache Tomcat Native library 1.1.27.
November 17 , 2013 10:31:17 PM org.apache.catalina.core.AprLifecycleListener init
INFO: APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
November 17 , 2013 10:31:18 PM org.apache.coyote.http11.Http11AprProtocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
November 17 , 2013 10:31:18 PM org.apache.coyote.ajp.AjpAprProtocol init
INFO: Initializing Coyote AJP/1.3 on ajp-8009
November 17 , 2013 10:31:18 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 1486 ms
November 17 , 2013 10:31:18 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
November 17 , 2013 10:31:18 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.29
November 17 , 2013 10:31:18 PM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor host-manager.xml
November 17 , 2013 10:31:18 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory docs
November 17 , 2013 10:31:19 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory examples
November 17 , 2013 10:31:19 PM org.apache.catalina.core.ApplicationContext log
INFO: ContextListener: contextInitialized ()
November 17 , 2013 10:31:19 PM org.apache.catalina.core.ApplicationContext log
INFO: SessionListener: contextInitialized ()
November 17 , 2013 10:31:19 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory kaoqintongji.myeclipse.bak
November 17 , 2013 10:31:19 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory ROOT
November 17 , 2013 10:31:19 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory test
November 17 , 2013 10:31:19 PM org.apache.coyote.http11.Http11AprProtocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
November 17 , 2013 10:31:19 PM org.apache.coyote.ajp.AjpAprProtocol start
INFO: Starting Coyote AJP/1.3 on ajp-8009
November 17 , 2013 10:31:19 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 830 ms

Here is my jsp page
header


Here is my xml file


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_3_0.xsd ">


This is the description of my J2EE component
This is the display name of my J2EE component
WorkDiaryServlet
com.control.WorkDiaryServlet


WorkDiaryServlet
/ WorkDiaryServlet.do



login.jsp


Here is my servlet files
package com.control;

import java.io.IOException;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class WorkDiaryServlet extends HttpServlet {

/ **
*
* /
private static final long serialVersionUID = 1L;

public void doGet (HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
}

public void doPost (HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String workId = request.getParameter ("workId");
String name = request.getParameter ("name");
String gender = request.getParameter ("gender");
String position = request.getParameter ("position");
String tel = request.getParameter ("tel");
String mail = request.getParameter ("mail");
String password = request.getParameter ("password");

System.out.println (workId + "" + name);
try {
Class.forName ("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e1) {
/ / TODO Auto-generated catch block
e1.printStackTrace ();
}
try {
Connection conn = DriverManager.getConnection ("jdbc: mysql :/ / localhost: 3306/workdiary", "root" , "123456" ) ;
Statement stmt = conn.createStatement ();
String sql = "INSERT INTO registerInf (workId, name, gender, position, tel, mail, password) VALUES ('" ; + workId + "','" + name + "','" + gender + "','" + position + "','" + tel + "','" ; + mail + "','" + password + "')";
System.out.println (sql);
stmt.executeUpdate (sql);

request.getRequestDispatcher ("/ zhuce.jsp"). forward (request, response);
} catch (SQLException e) {
/ / TODO Auto-generated catch block
e.printStackTrace ();
}
}
}
------ Solution ----------------------------------- ---------
form expression should not be a post submission method you
------ Solution ------------------- -------------------------
is estimated that you have several applications under tomcat submission address not add a slash "/" ; it

changed

------ Solution ------ --------------------------------------
you this question is really very simple way said first aciton there do not add / , your configuration is not wrong, mostly your submission using the get method, and submit to the background after you get there because there is no code block , it is blank , so that request is not completed it , you get a code block inside with one on it.
doPost (request, response); so ok ah
to the sub yo, follow me can solve
------ For reference only ------------------------ ---------------
[ sorry ] problem xml file shows a problem, this is the whole . thank you

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_3_0.xsd ">


This is the description of my J2EE component
This is the display name of my J2EE component
WorkDiaryServlet
com.control.WorkDiaryServlet



WorkDiaryServlet
/ WorkDiaryServlet.do


login.jsp


------ For reference only --------------------------- ------------


Positive Solutions
------ For reference only --------------------------------- ------

get or post is not the key issue
------ For reference only ---- -----------------------------------

get or post ; 's not the point  

At least you get to submit the page ,
public void doGet (HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
}
doGet there should be operating it
------ For reference only ---------------------------- -----------


http404 solve the problem , thank you !
But now I fill out the registration information, click submit display is blank , to go to view the database table did not respond .
my servlet in connection statement is : Connection conn = DriverManager.getConnection ("jdbc: mysql :/ / localhost: 3306/workdiary", "root", "123456" ) ;
This is my inside workdiary name of the database , the database name is under the table registerinf, I will not be writing these two problems ?
------ For reference only -------------------------------------- -
Click Submit display is blank , to go to view the database table did not respond . There may be questions submitted transaction , executed again when you put your last transaction auto-commit ,
PS database connection is not closed, the result set not related
------ For reference only ------------------------ ---------------

get or post is not the key issue          
  
At least you get to submit the page ,   
public void doGet (HttpServletRequest request, HttpServletResponse response)   
throws ServletException, IOException {   
}   
doGet there should be operating it  
yes ah, here refers to the doPost method should go inside .
You can try to break inside , since the 404 has been resolved , I think this next breakpoint you can own it . It is not enough, you can see there is no connection Connection problem .
------ For reference only -------------------------------------- -
first SQL statement COPY MYSQL management tools to run in next see if I can insert,

Or conn is null not even on the printed look under conn is not null

Or print out sql splicing error sql, COPY MYSQL management tools to run in under the watch can not be inserted

Or exterior field requires mandatory and did not pass over the value



------ For reference only ---------------------------------- -----
add, because you do is log in , so it is best to use the post method to submit data, or else you get used submission , others will see your data , of course, if you are like they saw it, then I would be no problem
------ For reference only --------------------------- ------------
positive solution
------ For reference only ---------------------- -----------------

get or post is not the key issue                
    
At least you get to submit the page ,     
public void doGet (HttpServletRequest request, HttpServletResponse response)     
throws ServletException, IOException {     
}     
doGet there should be operating it          
yes ah, here refers to the doPost method should go inside .   
You can try to break inside , since the 404 has been resolved , I think this next breakpoint you can own it . It is not enough, you can see there is no connection Connection problem .  

Your suggestion is correct, and the post before I get to ignore the problem has been solved now thank you
------ For reference only - -------------------------------------

Thank you for your question already told you solve the same
------ For reference only --------------------------- ------------
positive Solutions  
Thank you this is indeed the correct answer
------ For reference only -------------------------- -------------
Well, remember to give me points yo

没有评论:

发表评论