Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Kerri Gonzalez   on Jul 06 In Java Category.

  
Question Answered By: Jarvia Miller   on Jul 06

I would have a servlet that would create  the XML.

1) Specify a URL in the action part of the form in the JSP
(e.g.
<FORM ID=mainform ACTION="/createxml" METHOD="post">
<input type=text name=age>
<input type=text name=fname>
<input type=text name=lname>
<select name=race>
<option value=1>White</option>
<option value=2>Black</option>
<option value=3>Hispanic</option>
</select>
</FORM>

2) Create a servlet (e.g. CreateXMLServlet.java) that gets the form
data from the JSP via the HTTPRequest object in the doPost method of
the servlet. Put the servlet in <webapproot>/WEB-INF/classes/servlets/

e.g.
package servlets;

...
void doPost(HTTPRequest request ...) {
...
String age  = request.getParameter("age");
String fname = request.getParameter("fname");
String lname = request.getParameter("lname");
String raceID = request.getParameter("race");

// Create xml  document from this data

3) Add a servlet to URL mapping in your <webapp-root>/WEB-INF/web.xml
file.

<servlet>
<servlet-name>createxml</servlet-name>
<servlet-class>servlets.CreateXMLServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>createxml</servlet-name>
<url-pattern>/createxml</url-pattern>
</servlet-mapping>

Share: 

 
 
Didn't find what you were looking for? Find more on Create an xml page from jsp Or get search suggestion and latest updates.


Tagged: