提交动作不会把我带到Servlet

时间:2014-12-15 18:17:40

标签: java jsp servlets

我有一个JSP页面,它有一个按钮AddTile,其值为value = submit, 按下此按钮时,我想将控件带到servlet这是JSP页面的表单部分

<form action="webservlets/DatabaseConnector" id="tileform" name="tileform" onsubmit="return validateForm()" method="Get">
        <fieldset>
            <div id="tiletype">
                <input type="radio" name="tile" id= "initial" value="initial" checked>
                <label for="initial">Initial tile</label>
            </div>
            <div id="tilefield">
                <label for="initlength" class="title">Length</label>
                <input type="text" id="initlength" name="initlength" size="8" title="Enter length of tile in metres" autofocus>
            </div>
            <div id="tilefield">
                <label for="initangle" class="title">Direction</label>
                <input type="text" id="initangle" name="initangle" size="8" title="Enter initial direction in degrees">
            </div>
            <div id="tilefield">
                <label for="init_x" class="title">x-coordinate</label>
                <input type="text" id="init_x" name="init_x" size="8" title="Enter starting position x-axis">
            </div>
            <div id="tilefield">
                <label for="init_y" class="title">y-coordinate</label>
                <input type="text" id="init_y" name="init_y" size="8" title="Enter starting position y-axis">
            </div>
        </fieldset>
            <p>
        <fieldset>
            <div id="tiletype">
                <input type="radio" name="tile" id="longitudinal" value="longitudinal" disabled>
                <label for="longitudinal">Longitudinal tile</label>
            </div>
            <div id="tilefield">
                <label for="longlength" class="title">Length</label>
                <input type="text" id="longlength" name="longlength" size="8" disabled>
            </div>
        </fieldset>
            <p>
        <fieldset>
            <div id="tiletype">
                <input type="radio" name="tile" id="curved" value="curved" disabled>
                <label for="curved">Curved tile</label>
            </div>
            <div id="tilefield">
                <label for="curveradius" class="title">Radius</label>
                <input type="text" id="curveradius" name="curveradius" size="8" disabled>
            </div>
            <div id="tilefield">
                <label for="curveangle" class="title">Angle</label>
                <input type="text" id="curveangle" name="curveangle" value="" size="8" disabled>
            </div>
        </fieldset>
            <p>
            <button type="reset" id="buttons" onclick="reset()">Clear </button>
            <button type="submit" id="buttons" name = "initial" value="initial">AddTile</button>
        </form>

我的Servlet位于src&gt; webservlets(包名)&gt; DatabaseConnector

这是我的servlet的代码

@WebServlet("/DatabaseConnector")
public class DatabaseConnector extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public DatabaseConnector() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("Servlet now connected"+request.getParameter("name"));
        // TODO Auto-generated method stub
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
    }

}

1 个答案:

答案 0 :(得分:0)

由于您使用的是GET方法,因此您可以更轻松地测试您的应用。根据您的web.xml,servlet url可能会更改。根据您的web.xml以及您的jsp文件位于jsp提交URL的位置可能会发生变化。

    服务器中的
  1. Run your servlet。查看您的浏览器显示的网址。
  2. 从浏览器提交您的。查看您的浏览器显示的网址。
  3. 1和2的网址应该相同。