2017-08-09 19 views
2

現在、私はWebアプリケーションのために働いています。実は私のコードはここにWebアプリケーションのサーブレットマッピング

<div class="article"> 
            <form action="currentcondition.do" method="post"> 
             <table> 
              <tr><td>Disease Name</td><td><input type="text" name="disease" required/></td></tr> 
              <tr><td>Status</td><td><select name="status"><option>-Select-</option> 
                 <option>Current : Currently has this</option> 
                 <option>Intermittent : Comes and Goes</option> 
                 <option>Past : No longer has this</option> 
                </select> </td></tr> 
              <tr><td>Start Date</td><td><input type="date" name="sdate"/></td><td>End Date</td><td><input type="date" name="edate"/></td></tr> 
              <tr><td>Hospital Name</td><td><input type="text" name="hname" /></td><td>Dr Phone</td><td><input type="text" name="dphone" maxLength="10"/></td></tr> 
              <tr><td>Note</td><td><textarea name="note"></textarea></td></tr> 
              <tr><td>Click here to</td><td><input type="submit" value="save"/></td></tr> 
             </table> 
            </form> 
       </div> 

currentcundition.doとしてアクションを呼び出す以下のようになっています。これはcurrentcondition.javaという名前のサーブレットプログラムだと思います。このサーブレット・プログラムをWebアプリケーションにマップする方法。

私のweb.xmlのコード

<servlet> 
    <servlet-name>PHP</servlet-name> 
    <servlet-class>com.controller.currentcondition</servlet-class> 
</servlet> 
<servlet-mapping> 
    <servlet-name>PHP</servlet-name> 
    <url-pattern>/PHP/currentcondition.do</url-pattern> 
</servlet-mapping> 

それはないです。私は、これはそれがcurrentcundition.java

@WebServlet(name = "currentcondition", urlPatterns = {"/currentcondition.do"}) 
public class currentcondition extends HttpServlet { 
    protected void processRequest(HttpServletRequest request, HttpServletResponse response) 
      throws ServletException, IOException { 
     response.setContentType("text/html;charset=UTF-8"); 
     PrintWriter out = response.getWriter(); 
     try { 

      String disease= request.getParameter("disease");    
      String abedisease= attributebasedencryption.getattributebasedencryptionInstance().stringToHex(disease); 
      request.setAttribute("abedisease", abedisease); 
      RequestDispatcher go = request.getRequestDispatcher("/savecurrentcondition.jsp"); 
      go.forward(request, response); 
     } 

編集という名前の私のサーブレットのコードで、ここで

をこだわって助けてください私は何を期待しているかを示しています。あなたは、あなたが直接=「がloginservlet」

+1

以下の回答を参照してください。https://stackoverflow.com/a/18889931/3270795 –

+0

私の質問を編集しました、今私を案内してください – dell

答えて

0

を案内してください。あなたのフォームにmethod="post"を使用しているので、doPostが呼び出されます。

+0

私の質問のセクションで私の編集を見てください、私に何をする必要があるか教えてください – dell

+0

あなたはポストメソッドをオーバーライド..また、urlPatterns = {"/ currentcondition"}を使ってフォームのdo部分を削除しても、自動的に正しいメソッドに転送されます。 –

+0

私はあなたに何を言ってもらえませんでした。 – dell

0

あなたのコードはdoPostの代わりprocessRequestであるべきアクションを定義することができ、あなたのサーブレットコードでこの

@WebServlet("/loginServlet") 
public class LoginServlet extends HttpServlet { 
     //your code 
} 

のような注釈を使用することができれば、私に

関連する問題