2

Currently I'm working for web application. Actually my code looks like below

<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>

here calling action as currentcundition.do. I think this is servlet program which naming as currentcondition.java. how to map this servlet program to my web application. please help I'm stuck here

This is my servlet code it named as 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);
        }

Edit:

my web.xml code

<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>

It is not showing what what I'm expecting. please guide me

dell
  • 21
  • 8

2 Answers2

0

If you could use annotations like this

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

on your servlet code, then you can directly define the action="loginServlet"

Juliyanage Silva
  • 2,529
  • 1
  • 21
  • 33
  • see my edit in my question section and please let me know what I need to do – dell Aug 09 '17 at 10:12
  • dont you have a get post methods overridden..? and just use the urlPatterns = {"/currentcondition"} remove the do part in the form as well, they will forwarded to the right methods automatically – Juliyanage Silva Aug 09 '17 at 10:20
  • I did not get you what you saying – dell Aug 09 '17 at 10:26
  • put this to servelt annotation urlPatterns = {"/currentcondition.do"} and change the form action accordingly without ".do" part. in servlet override the doPost method so that it can handle POST requests – Juliyanage Silva Aug 09 '17 at 10:35
  • I have Edited my question, Now please guide me – dell Aug 09 '17 at 10:40
0

Your code should be in doPost instead of processRequest method, as doPost will be called because you are using method="post" in your form.

QuakeCore
  • 1,886
  • 2
  • 15
  • 33