Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Create an xml page from jsp

  Asked By: Kerri    Date: Jul 06    Category: Java    Views: 2500
  

How would I create an xml document from a jsp page.

So if a person signs up [ie reg page], how would i get those fields,
so lets age, race,fname and get that info and turn it into an xml
document?

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Jarvia Miller     Answered 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>

 
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: