鱼C论坛

 找回密码
 立即注册
查看: 4042|回复: 3

java servlet的小问题

[复制链接]
发表于 2013-10-13 15:48:47 | 显示全部楼层 |阅读模式
1鱼币
输入正确的用户名和密码后出现HTTP Status 405 - HTTP method GET is not supported by this URL

//LoginServlet.java代码

package com.cj.view;


import javax.servlet.*;

import javax.servlet.http.*;


import java.io.*;




public class LoginServlet extends HttpServlet {

public void doGet(HttpServletRequest request,HttpServletResponse response)

throws ServletException,IOException{

response.setContentType("text/html;charset=utf-8");

response.setCharacterEncoding("utf-8");

PrintWriter out = response.getWriter();

out.println("<h1>用户登录</h1>");

out.println("<form action='/UsersManger1/LoginCLServlet' method='POST'>");

out.println("用户名<input type='text' name='username' /><br>");

out.println("密 码<input type='password' name='password' /><br>");

out.println("<input type='submit' value='登录' /><br>");

out.println("</form>");



}


public void doPost(HttpServletRequest request,HttpServletResponse response)

throws ServletException,IOException{


this.doGet(request, response);


}




}


//LoginCLServlet.java的代码

package com.cj.contraler;


import javax.servlet.*;

import javax.servlet.http.*;


import java.io.*;


/**

* Servlet implementation class LoginCLServlet

*/

public class LoginCLServlet extends HttpServlet {

public void doGet(HttpServletRequest request,HttpServletResponse response)

throws ServletException,IOException{


response.setContentType("text/html;charset=utf-8");

PrintWriter out = response.getWriter();

String username=request.getParameter("username");

String password=request.getParameter("password");


System.out.print(username+" " +password);

if("abc".equals(username)&&"123456".equals(password))

response.sendRedirect("/UsersManger1/MainFrame");

else

response.sendRedirect("/UsersManger1/LoginServlet");



}

public void doPost(HttpServletRequest request,HttpServletResponse response)

throws ServletException,IOException{


this.doGet(request, response);


}


}


//MainFrame.java的代码

package com.cj.view;

import javax.servlet.*;

import javax.servlet.http.*;


import java.io.*;



public class MainFrame extends HttpServlet{

public void doGet(HttpServletResponse request,HttpServletResponse response)

throws ServletException,IOException{


response.setContentType("text/html;charset=utf-8");

PrintWriter out = response.getWriter();

out.println("<h1>主界面 </h1>");


}


public void doPost(HttpServletRequest request,HttpServletResponse response)

throws ServletException,IOException{


this.doGet(request, response);


}



}




最佳答案

查看完整内容

能看到的错去就是MainFrame中的doGet方法的2个参数都写成了HttpServetResponse 把第一个参数修改下应该就Ok
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2013-10-13 15:48:48 | 显示全部楼层
能看到的错去就是MainFrame中的doGet方法的2个参数都写成了HttpServetResponse 把第一个参数修改下应该就Ok

评分

参与人数 1荣誉 +5 鱼币 +5 贡献 +1 收起 理由
springwindyike + 5 + 5 + 1 热爱鱼C^_^

查看全部评分

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2013-10-13 15:50:44 | 显示全部楼层
//web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>UsersManger1</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  <servlet>
    <description></description>
    <display-name>LoginServlet</display-name>
    <servlet-name>LoginServlet</servlet-name>
    <servlet-class>com.cj.view.LoginServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>LoginServlet</servlet-name>
    <url-pattern>/LoginServlet</url-pattern>
  </servlet-mapping>
  <servlet>
    <description></description>
    <display-name>LoginCLServlet</display-name>
    <servlet-name>LoginCLServlet</servlet-name>
    <servlet-class>com.cj.contraler.LoginCLServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>LoginCLServlet</servlet-name>
    <url-pattern>/LoginCLServlet</url-pattern>
  </servlet-mapping>
  <servlet>
    <description></description>
    <display-name>MainFrame</display-name>
    <servlet-name>MainFrame</servlet-name>
    <servlet-class>com.cj.view.MainFrame</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>MainFrame</servlet-name>
    <url-pattern>/MainFrame</url-pattern>
  </servlet-mapping>
</web-app>

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2014-9-30 09:12:33 | 显示全部楼层
请用jsp做视图,  servlet只适合做控制器
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-11-14 13:00

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表