Several error fixes for HTTP Status * * in eclipse running the servlet

Source: Internet
Author: User

These two days have been in tune Eclipse, running a servlet simple program but there will be a number of errors, online search a lot, we ramble, but a variety of solutions do not have a suitable for me, after a whole day of efforts, finally resolved, is to share the author, I hope the vast number of people to scold farmers

The first thing I want to say is that I'm using the Eclipse JAVA EE version of the platform, and the myeclipse stuff may not be applicable. The JDK version is 1.7 and the Tomcat version is 6.0 (the emphasis here should be eclipse3.x, JDK1.6, tomcat6.0 collocation or eclipse4.x, JDK1.7, tomcat7.0 collocation, but I was confusedly installed, and then use tomcat7.0 instead of version 6.0, running the servlet will appear HTTP Status 500 error, is estimated to eclipse in the plug-in and Tomcat conflict problem, Because the plugin for WTP is from the HTTP://BLOG.CSDN.NET/TIANSONG04 blog, it is based on the tomcat6.0 version. So here to remind the broad and I like the rookie pots Friends, version collocation saves you to find the wrong half of the time, do not step in my footsteps.

First build dynamic Web Project, which creates 3 files, a.jsp:

B.JSP:
<% 
		String error_message= "";
		Object Error=request.getattribute ("error");
		if (error!=null) error_message=error.tostring ();
	%>
	<form action= "HelloServlet" >
		<table cellspacing= "4" >
			<tr>
				<td> Enter your user name:</td>
				<td><input name= "user" type= "text" size= "M" ></td>
				<TD Style= "color:red" ><%= error_message%></td>
			</tr>
			<tr>
				<td></ td>
				<td><input type= "Submit" value= "Login" ></td>
				<td></td>
			</ tr>
		</table>
	</form>


Helloservlet.java (servlet file)

	protected void doget (HttpServletRequest request, httpservletresponse response) throws Servletexception, IOException c1/>//TODO auto-generated Method stub
		String url= "/a.jsp";
		String user=request.getparameter ("user");
		if (user==null| | User.length () ==0)
		{
			url= "/b.jsp";
			Request.setattribute ("Error", "User name must not is empty.");
		}
		
		ServletContext Context=getservletcontext ();
		RequestDispatcher dispatcher=context.getrequestdispatcher (URL);//The Forward method that invokes the RequestDispatcher class is transferred to the URL
		Dispatcher.forward (request, response);
	


Concrete implementation is actually the value of the page to judge. Right-click the Helloservlet.java file and use the debug on server

The first occurrence is the HTTP status 404~:

The reason is probably 1: your HelloServlet file location is problematic and can be adjusted. 2: Your Tomcat setup issues re-use the remove operation from the Window->preference->server in Eclipse, and then rebuild the server. 3: It was a method I saw and solved the problem temporarily: excerpted from http://blog.csdn.net/alexhan_bing/article/details/2457891

If you are performing the 3rd method of uncomment above, you may receive the following error "server Tomcat v6.0 server at localhost failed to start."

So you need to do the following things: 1. Modify the Tomcat6.0/conf/context.xml file and add two new properties.
<context reloadable= "true" privileged= "true" >
<!--Default set of monitored resources-->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
</Context> 2. Restart Eclipse, this step is very important, must do after the normal operation, then congratulations, if there are HTTP Status404 errors, please look at the Dynamic Web project you created build/ Whether the. class file that has the same name as the servlet is generated under classes, and if not, then you need to check that project in the menu item has the build automatically set, and recompile after setting will generate. class. The problem is solved at this time. Result diagram:

Finally, I hope that this post is helpful to everyone, if there are errors or omissions also hope that you can make corrections, to come to see affixed to provide convenient, less detours

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.